Modern Education

Dynamic Memory Allocation QA

Dynamic Memory Allocation QA



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char *s;
    s=malloc(26);
    strcpy(s, "ptinstitute.in");
    printf("%s\n",s);
    return 0;
}

options:
A. ptinstitute.in
B. 0
C.compiler error
D. runtime error


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s;
    s=malloc(26);
    strcpy(s, "good morning");
    free(s);
    printf("%s\n",s);
    return 0;
}
options:
A. good morning
B. garbage string
C. comipler error
D. rutime error


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s;
    s=malloc(26);
    s=NULL;
    strcpy(s,"good");
    printf("%s\n",s);
    return 0;
}

options:
A. runtime error
B. good
C. 0
D. compiler error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s;
    s='g';
    printf("%s\n",s);
    return 0;
}

options:
A. compiler error
B. 0
C. g
D. run time error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int *foo(void)
{
    int x=22;
    return &x;
}

int main()
{
    int *w;
    *w=foo() ;
    printf("\n %d", *w);
    return 0;
}


options:
A. 0
B. 22
C. run time error
D. garbage value


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int foo(int *s)
{
    int *x=s;
    return *x;
}

int main()
{
    int w[1]={23};
    w[0]=foo(w) ;
    printf("\n %d", *w);
    return 0;
}


options:
A. run time error
B. 23
C. 0
D. garbage value


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int* foo(int *s)
{
    int *x=s;
    x++;
    return x;
}

int main()
{
    int w[4]={56,3,44,5};
    int *p;
    p=foo(&w[0]) ;
    printf("\n %d", *p);
    return 0;
}

options:
A. 44
B. 56
C. 3
D. run time error


Ques 8. what is the output for the below code?
int * foo(int *s)
{
    s=(int *)malloc(4);
    return s;
}

int main()
{
    int *p;
     p= foo(p);
    *p=283;
    printf("\n %d", *p);
    return 0;
}

options:
A. 283
B. 284
C. run time error
D. compiler error 


Ques 9. what is the output for the below code?
int main()
{
    int *p;
     p= (int *)malloc(4);
    *p=283;
    ++*p;

    printf("\n %d", *p++);
    return 0;
}


options:
A. 281 
B. 283
C. 285
D. 284


Ques 10. what is the output for the below code?
int main()
{
    int  *q;

     q=calloc(12,1);
    *q=54;
    *(++q)=78;

    printf("\n %d %d", *(--q), *(q));
    return 0;
}

options:
A. run time error
B. 54 78
C. 55 79
D. 53 77


Ques 11. what is the output for the below code?
int main()
{
    int  *q[2];

     q[0]=calloc(4,2);
     q[1]=calloc(4,2);
    **q=54;
    *q[1]=58;
     ++(*q[1]);

    printf("\n %d %d",  **q, *q[1]);
    return 0;
}

options:
A. 55 58
B. 54 58
C. 54 59
D. run time error


Ques 12. what is the output for the below code?
int main()
{
    int  *q[2];

     q[0]=(int *)calloc(4,2);
     q[0]=(int *)realloc(q[0], 20);

    **q=54;
    ++**q;
    *(q[0]+3) = 78;
    --(*(q[0]+3));

    printf("\n %d %d",  **q, *(*q +3));
    return 0;
}


options:
A. 54 78
B. 55 77
C. 54 78
D. run time error


Ques 13. what is the output for the below code?
int main()
{
    int  ****p;
    int  ***q;
    int  **r;
    int  *s;

   s=(int *)malloc(4);
   r=&s;
   q=&r;
   p=&q;

   *s=47;

    printf("\n %d %d %d %d",  *s, **r, ***q, ****p);
    return 0;
}


options:
A. run time error
B. 47 46 47 0
C. 46 45 0 0
D. 47 47 47 47


Ques 14. what is the output for the below code?
int main()
{
    int  ****p;
    int  ***q;
    int  **r;
    int  *s;

   s=(int *)malloc(4);
   r=&s;
   q=&r;
   p=&q;

   *s=47;
   ++**r;
   ++***q;
   ++****p;

    printf("\n %d %d %d %d",  *s, **r, ***q, ****p);
    return 0;
}

options:
A.47 47 48 47 
B.50 50 50 50
C. 47 46 50 47
D. 47 48 49 59


Ques 15. what is the output for the below code?
int main()
{
    int  *s;
    s=(int *)calloc(4, 5);
    *s=45;
    s++;
    *s=56;
    *s=++(*s);

    printf("\n %d %d ",  *s, *(s-1));
    return 0;
}
options:
A. 45 57
B. 56 45
C. 57 45
D. 45 56


Ques 16. what is the output for the below code?
int main()
{
    int  *s;
    s=(int *)calloc(4, 2);
    s=realloc(s, sizeof(int)*4);
    *s=45;
    s++;
    *s=56;
    *s=++(*s);
    *(++s) =78;
    *(++s) =97;

    printf("\n %d %d %d %d",  *s, *(s-1), *(s-2), *(s-3));
    return 0;
}

options:
A. 57 97 45 57
B. 78 97 45 57
C. 97 78 57 45
D. 45 57 78 97


Ques 17. what is the output for the below code?
int main()
{
    int  *s[1];
    *s = (int *)malloc(4);
    *s = realloc(*s, sizeof(int)*3);
    **s = 45;
    ++(*s);
    **s=56;
    *(++(*s)) =78;
    *(++(*s)) =97;

    printf("\n %d %d %d %d",  **s, *(*s-1), *(*s-2), *(*s-3));
    return 0;
}
options:
A. 45 56 78 97 
B. 97 78 56 45
C. 45 56 97 78
D. 56 45 78 97


Answers

1. A 2. B 3. A 4. D 5. C 6. B 7. C 8. A 9. D 10. B 11. C 12. B 13. D 14. B 15. C 16. C 17. B

Advanced Pointers

Advanced Pointers



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int * add(int *p, int *q)
{
 int sum;
  sum=*p+*q;
  return ∑
}

int main()
{
  int r = 20, s=3;
  int *sum;
  int *p = &r, *q=&s;

  sum=add(p, q);

  printf("%d ", *sum);
  return 0;
}

options:
A. runtime error
B. 23
C. 0
D. compiler error



Ques 2. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int * add(int *p, int *q)
{
 int *sum =(int*)malloc(4);
  *sum=*p+*q;
  return sum;
}

int main()
{
  int r = 20, s=3;
  int *sum;
  int *p = &r, *q=&s;

  sum=add(p, q);

  printf("%d ", *sum);
  return 0;
}

options:
A. compiler error
B. runtime error
C. 23
D. 0


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

void swap(int *p, int *q)
{
 int t;
 t=*p;
 *p=*q;
 *q=t;
}

int main()
{
  int r = 20, s=3;
  int *p = &r, *q=&s;

  swap(p, q);

  printf("*p=%d *q=%d", *p, *q);
  return 0;
}

options:
A. *p=20 *q=3
B. runtime error
C. *p=3 *q=20
D. compiler error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void swap(int *p, int *q)
{
 int t;
 t=p;
 p=q;
 q=t;
}

int main()
{
  int r = 20, s=3;
  int *p = &r, *q=&s;

  swap(p, q);

  printf("*p=%d *q=%d", *p, *q);
  return 0;
}

options:
A. compiler error
B. *p=20 *q=3
C. *p=3 *q=20
D. run time error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
  int r = 20, s=3;
  int *p = r, *q = s;

  printf("*p=%d *q=%d", *p, *q);
  return 0;
}

options:
A. 3, 20
B. 20, 3
C. compiler error
D. runtime error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
   int (*q)[5];
   printf("%d",  sizeof(*q));
   return 0;
}

options:
A. compiler eror
B. 4
C. 20
D. runtime error


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{

   int (**q)[4] ={3,4,5,6,7,6};
   printf("%d",  sizeof(**q));
   return 0;
}

options:
A. 4
B. 16
C. 24
D. runtime error



Ques 8. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int q[2][3][2] ={3,4,5,6,7,6};
   printf("%d",  sizeof(q));
   return 0;
}

options:
A. 20
B. 24
C. 4
D. 48


Ques 9. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int q[6] ={3,4,5,6,7,6};
   int *r=(q+1);
   printf("%d %d",  *(r+2), *r++);
   return 0;
}

options:
A.
B.
C.
D.


Ques 10. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int q[6] ={3,4,5,6,7,6};
   int *r=(q+1);

   printf("%d %d",  *(r+2), *r++);
   return 0;
}

options:
A. 7, 4
B. 6, 4
C. 5, 4
D. 5, 6


Ques 11. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int p =32;
   int *q=&p;
   int **r=&q;

   printf("%d %d",  **r, *q);
   return 0;
}

options:
A. 32 32
B. 0 0
C. grabage value
D. runtime error



Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int p =32;
   int *q=&p;
   int **r=q;

   printf("%d %d",  **r, *q);
   return 0;
}

options:
A. 32 32
B. 0 0
C. grabage value
D. runtime error



Ques 13. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+2, p+3};
   int ***r=q;

   printf("%s %s",  **r, **(r+1));
   return 0;
}

options:
A. good test
B. welcome good
C. welcome test
D. test good


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};
   int ***r=q;
   r++;
   printf("%s %s",  **r, **(r+1));

   return 0;
}

options:
A. computer ptinstitute.in
B. ptinstitute.in computer
C. welcome good
D. runtime error



Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  ++(*p), *(p+2));

   return 0;
}

options:
A. good test
B. welcome test
C. elcome test
D. ood test


Ques 16. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  **q, **(q+2));

   return 0;
}

options:
A. test computer
B. welcome test
C. welcome good
D. good computer


Ques 17. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  *(*q++), **(q+2));

   return 0;
}
options:
A. compiler error
B. runtime error
C. welcome good
D. good test


Ques 18. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  *(*q)++, **(q+2));

   return 0;
}
options:
A. compiler error
B. runtime error
C. welcome good
D. good computer


Ques 19. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};
p[1]= p[1] + 2;
p[3]= p[0] + 4;
   printf("%s %s",  *(*q)++, **(q+2));

   return 0;
}

options:
A. od mputer 
B. runtime error
C. welcome good
D. od ome



Ques 20. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

void fun( char *p)
{
    printf("\n %s", ++p);

}
int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   fun(p[2]);
   return 0;
}


options:
A. est 
B. runtime error
C. compiler error
D. test



Answers

1. A 2. C 3. C 4. B 5. D 6. C 7. B 8. D 9. C 10. A 11. A 12. D 13. A 14. B 15. C 16. D 17. A 18. D 19. D 20. A

C Operator Q&A

C operators Q & A


Ques 1. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m,n,p;

    m=(1,2,3);
    p =1,2,3;

    printf("i = %d\n",m+p);
    return 0;
}

options:
A. 4
B. 2
C. 6
D. compile time error



Ques 2. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x=2,y=2,z=1,k=4, h=3;

    z+=x==y=k==h;

    printf("Hello world! %d\n",z);
    return 0;
}

options:
A. 2
B. compiler error lvalue required 
C. 3
D. 4


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x=2,y=2,z=1,k=4, h=3;

    z+=x==(y=k==h);

    printf("%d\n",z);
    return 0;
}

options:
A. 2
B. 0
C. 1
D. compiler error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz=2,3,4;

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 9
B. 8
C. 7
D. compiler error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz=(2,3,4);

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 7
B. 9
C. 8
D. compiler error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    ++mn++;

    printf("%d\n",mn);
    return 0;
}

options:
A. 6
B. compiler error
C. 7
D. 8


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz;
    xyz=2,3,4;

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 9
B. 8
C. 7
D. compiler error


Ques 8. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    ++mn;

    printf("%d\n",mn++);
    return 0;
}

options:
A. 8
B. 7
C. 6
D. compiler error


Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5,y,z,s;
    mn = (y=mn++) + (z=mn++) + (s=++mn);

    printf("%d\n",mn++);
    return 0;
}

options:
A. 19
B. 21
C. 22
D. compiler error


Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    mn = mn++ + mn-- + --mn;

    printf("%d\n",mn++);
    return 0;
}

options:
A. 16 
B. 14
C. 15
D. compiler error



Ques 11. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5, y=3;

    printf("%d\n",mn>y? 22:44);
    return 0;
}
options:
A. 44
B. 22
C. 5
D. 3



Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int *m, int *n)
{
    int sub = *m-*n;
    *m=*n;
    return *m+*n;

}
int main()
{
    int *a,*b;
    int x=22,y=3;

    a=&x; b=&y;

    printf("%d\n",fun(a,b));
    return 0;
}

options:
A. 6
B. compiler error
C. 22
D. 8



Ques 13. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int *m, int *n)
{
    int sub = *m-*n;
    *m=*n;
    return *m+*n;

}
int main()
{
    int *a,*b;
    a=(int *)malloc(4);
    b=a;

    *a=3; *b=5;

    printf("%d\n",fun(a,b));
    return 0;
}
options:
A. 8
B. 10
C. 13
D. compiler error


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

void fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
}
int main()
{
    int *a,*b;
    a=(int *)malloc(4);
    b=a;

    *a=3; *b=5;
    fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. 3 5
B. 5 3
C. 5 5
D. compiler error


Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

void fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
}
int main()
{
    int *a,*b;
    a=(int *)malloc(sizeof(int)*2);
    b=a;

    *a=3; *b=5;
    *a = *b && fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. compiler error
B. 1 5
C. 5 5
D. 5 1


Ques 16. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
    return *m=*n;
}

int main()
{
    int *a,*b;
    a=(int *)malloc(sizeof(int)*2);
    b=a;

    *a=3; *b=5;
    *a = *b && fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. compiler error
B. 1 1
C. 5 5
D. 3 3 


Ques 17. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;

    a=3; b=5;
    b = sizeof( a *= b+5);

    printf("%d %d\n",a, b);
    return 0;
}

options:
A. 3 5
B. 3 20
C. 3 4
D. compiler error

Ques 18. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d;
    a = 5; b=4; d=7;

    c=a & b | d;

    printf("%d \n", c);
    return 0;
}

options:
A. 7
B. 5
C. 4
D. compiler error



Ques 19. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d, e=6;
    a = 5; b=4; d=7;

    c=a & b | d ^ e;

    printf("%d \n", c);
    return 0;
}

options:
A. 4
B. 7
C. 5
D. compiler error

Ques 20. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d, e=2;
    a = 5; b=4; d=7;

    c=a >> b | d << e;

    printf("%d \n", c);
    return 0;
}

options:
A. 22
B. 28
C. 7
D. compiler error




Answers

1. A 2. B 3. C 4. D 5. B 6. B 7. C 8. C 9. A 10. C 11. B 12. A 13. B 14. C 15. A 16. B 17. C 18. A 19. C 20. B

Misc QA

MiSC QA



Ques 1. what is token? 

A. each and every units in c program are called tokens .
B. only variables
C. only constants
D. only function names


Ques 2. what are different types of token?




Ques 3. count number of tokens in the below code statement?

scanf("%d", &x);
options:
A. 7
B. 3
C. 6
D. 5


Ques 4. what type of language is c?

options:
A. it is high level language
B. it is low level language
C. it is a high level language with support to low level programming
D. it is super high language



Ques 5. if character size is 1 byte predict the output?

#include <stdio.h>
#include <stdlib.h>
char printchar()
{
  putchar('D');
  return 'D';
}
int main()
{
    printf("%d", sizeof(printchar()));

    return 0;
}

options:
A. 1
B. D 1
C. 1 D
D. compiler error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[][4] = {1,2,3,4,5,6,7,8} ;
int (*p)[4] = arr;

printf("%d, %d ", *((*p)+1), *((*p)+2));
++p;
printf("%d, %d ", (*p)[1], (*p)[2] );

    return 0;
}

options:
A. 2,3, 6,7
B. 1,2,3,4
C. 5,6,7,8
D. 1,2,5,6 


Ques 7. what is the answer for the for loop line in the below code?
#include <stdio.h>
#include <stdlib.h>

main()
{
 int index;
for(index=0, index<5, index++);
}

options:
A. lexical error
B. only syntax error
C. No compiler error
D. both lexical and syntax error


Ques 8. In C program when the macro defined is resolved?

options:
A. preprocessing time
B. compiling time
C. during linking
D. run time


Ques 9. In C program two files f1 and f2 are present, a funtion present in f2 is called in file f1.
when this is resolved?

options:
A. preprocessing time
B. compiling time
C. during linking
D. run time



Ques 10. In C program a variables declared defined, when this is resolved?

options:
A. preprocessing time
B. compiling time
C. during linking
D. run time


Ques 11. for the below code what is the right way of accessing the data?

int x,y,z;
int *mdn[4], xrg[2][3];

options:
A. mdn[1] = &x, xrg[1]=34
B. mdn[1] = &x, xrg[1][0]=34
C. mdn[4] = &x, xrg[3]=34
D. mdn[1] = &x, xrg[4]=34


Ques 12. what is the option correct for c language?

options:
A. it case insensitive language
B. a regular language
C. it case sensitive language
D. low level language


Ques 13. how the c language processing happen?

options:
A. preprocessing, compilation, linking
B. compilation, preprocessing, linking
C. linking, compilation, preprocessing
D. linking , preprocessing, compilation


Ques 14. what is the command for getting preprocessed file in linux?

options:
A. gcc -k filename.c
B. gcc -E filename.c
C. gcc -l filename.c
D. gcc -p filename.c


Ques 15. what is the command for getting object code file in linux?

options:
A. gcc -S filename.c
B. gcc -E filename.c
C. gcc -o filename.c
D. gcc -c filename.c


Ques 16. what is the command for getting assembly code file in linux?

options:
A. gcc -S filename.c
B. gcc -E filename.c
C. gcc -o filename.c
D. gcc -c filename.c


Ques 17. what is the command for getting outputfile after linking files in linux?

options:
A. gcc -S filename.c
B. gcc -E filename.c
C. gcc -o filename.c
D. gcc -c filename.c


Ques 18. what is the output for the following program?

#include <stdio.h>
#include <stdlib.h>

int disp(int m, int n)
{
    int p=m+n;
    printf("\n m = %d", m);
    return p;
}
int main()
{
    int p=3,q=4, k;
   int (*f)(int, int);
    f=disp;
    k=f(p,q);
printf("\n k= %d",k);
    return 0;
}

options:
A. 3 7
B. compiler error
C. runtime error 
D. 7 7 


Ques 19. what is the output for the following program?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int p=0x55 ;
    p = 0xb>>1<<2;
    printf("\n p= %x",p);
    return 0;

}

options:
A. a8
B. compiler error
C. runtime error 
D. 14 


Ques 20. what is the output for the following program?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int p=0x55 ;

     p = (p & 0xff) & (~(1<<2)) ;

     printf("\n p= %x",p);

    return 0;
}


options:
A. 51
B. 54
C. 58
D. 55 



Answers

1. A 2. the different types of tokens are Keywords (ex. int float while, case), Identifiers(ex. main, sum, total), Contants(ex, 44,67) strings (ex: "sum", "welcome", "ptinstitute.in" ) Special symbols (ex: (), {}) Operators (ex: +,-,/, *) 3. 7 4. C 5. 1 6. A 7. B 8. A 9. C 10. B 11. B 12. C 13. A 14. B 15. C 16. A 17. C 18. A 19. D 20. A

Interview Q & A

Interview QA



1. What is Recursion ? 
	A function calling to itself is called recursion. 
Some time stack may overflow if we are not properly exit the recursion function.
stack may overflow if the recursion function calling chain goes very long.
so the runtime error will occur.

ex:
main()
{
int sum;
sum=add(a,b);

}

add(int a, b)
{
int sum=0;
sum = a+b;
if (a>100)
return sum;

add();

}



2. What is stack overflow.?
	stack going outside its maximum range is called stack overflow.
say if stack size 1000 bytes, if the program is writing after 1000 bytes
memory reservered for stack is called stack overflow.
due to this runtime error will occur.



3. what is itoa() function?

  itoa() converts integer to character.

Ex: 
int x=222 
char buf[20]
iota(x,buf, 10); //decimal number to string
iota(x,buf, 2); //binary number to string
iota(x,buf, 16); //hexadecimal number to string


	
4. what is atoi() function?
  atoi function converts string to integer.

ex:
char str="32322";
num=atoi(str);



5. write your own funtion itoa(), atoi() ?



6. what is bigendian?

  	The  data present in the variable, if it stores Higher byte first in memory is called bigendian.
ex: var =0x44556677 

in memory it stores first 44 then --55 --66 --77
ex: 0xffff0000 = 44
    0xffff0001 = 55
    0xffff0002 = 66
    0xffff0003 = 77 



7. what is little endian?

  	The  data present in the variable, if it stores Lower byte first in memory is called little endian.
ex: var =0x44556677 

in memory it stores first 77 then --66 --55 --44

ex: 0xffff0000 = 77
    0xffff0001 = 66
    0xffff0002 = 55
    0xffff0003 = 44 



8. What is memory leak?
   If the memory is allocated using malloc, calloc etc after using it has to be freeed
if that memory is not used more.

if that memory is not freeed then it is called memory leakage.



9. Segmentation fault?
It is caused by the program writing and reading memory in illegal memory location is called segmentation fault.
say a read only location, or writing the non existing array element.
it causes the runtime error.



10. Dangling pointer?
   If a pointer is allocated a memory then after using it is deallocated. 
The pointer still pointing to the same meory location, but it is unreserved for it now.
if this pointer is accessed then unpredictable behavior accours, this is called dangling pointer .
it causes runtime error.



11. what is token?

each word say keyword, symbols, variables, ; , etc in a c program is called token.
there are 6 types of token
 
  - keywords  ex: int, float, switch, case, if, else etc
  - operators ex: +, -, *, /, %, |, &, ^, || etc
  - strings  ex: "sum = %d, avg= %f", "total = " 
  - Identifiers(ex. main, sum, total), 
  - Contants(ex, 44,67)
  - Special symbols (ex: (), {})



12. what is forward reference?

    Refering to the label before its declaration is called forward reference.


goto SUM;

SUM:
 ------
 -----

File Handling in C

C FILE HANDLING



Ques 1. what is the meaning of the statement ?

FILE *fileptr;

options:
A. fileptr is a integer pointer.
B. fileptr is pointer
C. FILE is a structure , fileptr is a pointer of type FILE.
D. error declaration.


Ques 2. what is the output written in the file samp.txt?

#include <stdio.h>
#include <stdlib.h>
FILE *fp;
int main()
{
    char str[30]="good";
    fp=fopen("samp.txt", "w");
    fprintf(fp, "%s",str );
    fclose(fp);

    printf("Hello world!\n");
    return 0;
}

options:
A. good
B. compiler error
C. runtime error



Ques 3. what is the value of EOF?

options:
A. none of the below
B. NULL
C. 0
D. -1


Ques 4. what is the meaning of r mode in c file opening?

options:
A. file is opened for read only
B. file is opened for write only
C. file is opened for write/read
D. none of the above


Ques 5. what is the meaning of "a" mode in c file opening?

options:
A. file is opened for read only
B. file is opened for write only
C. file is opened for append mode
D. none of the above


Ques 6. what is correct for about getc in below options?

options:
A. getc() read till EOF or finds error on reading a character.
B. getc() just read a character from standard input
C. getc read a character from a file.
D. none of the above 


Ques 7. why is fseek is used?

options:
A. fseek moves the file ptr to the beginning of the file.
B. fseek moves the file ptr to the end of the file.
C. fseek moves the file ptr to the required location of the file.
D. all of the above.


Ques 8. what are the file opening modes in c?

options:
A. w,r,a, r+, w+
B. only w, r
C. only w, a
D. none of the above.


Ques 9. what fclose() funtion will do in c?

options:
A. it closes the stream and all the structure associated with it.
B. it exits the program 
C. It exits from the fucntion
D. none of the above


Ques 10. what is the output for the below code?
#include < stdio.h>
#include < stdlib.h>

FILE *fp;
int main()
{
    char str[30]="good";
    int data = 456;
    fp=fopen("samp.txt", "w");

    fprintf(fp, "%s = %d",str,data );
    fclose(fp);

    return 0;
}


options:
A. 456 = good
B. good = 456
C. compiler error
D. runtime error



Answers

1. C 2. A 3. D 4. A 5. C 6. A 7. D 8. A 9. A 10. B

Variables in Depth

C Variables



Ques 1. what is the scope of var1 and var2?

int var1;
fun()
{
	int var2;
}

options:
A. The scope of var2 is accessible through out the file and var1 is accessible only inside the fun.
B. The scope of var1 is accessible through out the file and var2 is accessible only inside the fun.
C. The scope of var1 and var2 are accessible only inside the fun().
D. The scope of var1 and var2 are accessible through out the file.


Ques 2. what is the life and scope of var1 and var2?

int var1;
fun()
{
	static int var2;
}

options:
A.  The life and scope of var1 and var2 are through out the file.
B.  The life and scope of var1 and var2 are only in fun().
C.  The life and scope of var1 is through out the file. The scope of var2 is inside the fun() and life exists till the
    program running.
D.  none of these


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int v=7;
int main()
{
    int v=v;
    if(v==7)
    printf("value of v = 7\n");
    else
    printf("value of v is garbage\n");
    return 0;
}

options:
A. value of v = 7
B. value of v is garbage
C. compiler error
D. runtime error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
extern int sum;
int main()
{
    int a,b;
    a=3, b=5;
    sum+=a+b;
    printf("%d ", sum);
    return 0;
}

options:
A. 8 
B. 20
C. 0
D. compiler error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
extern int var = 0;
int main()
{
    if(var!=0)
        printf("\n var is not 0");
    else
        printf("\n var is 0");
    return 0;
}
options:
A. var is 0
B. var is not 0
C. compiler error
D. runtime error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    {
      int avg=0;
    }
    if(avg==0)
        printf("\n avg = %d",avg);
    return 0;
}
options:
A. avg =0
B. Compiler error
C. runtime error
D. none of these


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int a=2,b=3;
int main()
{
    float m=33.4;
    {
      int p=33;
      m=m+b;
    }
    printf("%f ", m);

    p=p+b;
    printf(" p= %d",p);
    return 0;
}

options:
A. runtime error
B. Compiler error
C. 36.4 36
D. 36.4  3



Ques 8. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int a=2,b=3;
int main()
{
    float m=33.4;
    {
      int p=33;
      m=m+b;
      b=p+b;
    }
    printf("%2.2f ", m);
    printf(" p= %d",b);
    return 0;
}

options:
A. 36.4 36
B. compiler error
C. runtime error
D. 33.4 3



Ques 9. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int x=035, y=0x15;
int main()
{
    printf("x=%d y=%d ", x,y);
    return 0;
}

options:
A. 35 21
B. 35 15
C. 29 21
D. none of these


Ques 10. which variable has highest scope?

#include <stdio.h>
#include <stdlib.h>

int x=35;

void fun()
{
   int y =33;
}
int z=33;
int main()
{
    int p=3;
    return 0;
}

options:
A. y
B. z
C. p
D. x



Ques 11. what is the valid variables in the below code?
#include <stdio.h>
#include <stdlib.h>
int 2x = 35;

int main()
{
    int mm_2 = 35;
    int _ = 6;

    return 0;
}

options:
A. 2x and mm_2
B. mm_2 _
C. 2x and _
D. mm_2 and _


Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int *p ;

int main()
{
    int *q=NULL;
    if(p=q)
        printf(" equal\n");
    else
        printf(" not equal\n");

    return 0;
}

options:
A. equal
B. not equal
C. compiler error
D. runtime error


Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int *p ;

int main()
{
    int *q=NULL;
    if(p==q)
        printf(" equal\n");
    else
        printf(" not equal\n");

    return 0;
}


options:
A. not equal
B. equal
C. runtime error
D. none of these


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int *p ;
void fun(int *m)
{
 *m=*m+5;
 printf("m = %d ",*m);
}

int main()
{
    int s=23;
    int *q=&s;
    fun(q);
    printf("q = %d", *q);
    return 0;
}

options:
A. 28 28
B. run time error
C. compiler error
D. 28 23


Ques 15. what is the output for the below code?
int p =43;
char q ='d';

int main()
{
    printf("%d", q);
    printf(" %0.2f", p);
    return 0;
}
options:
A. 100 0.00
B. d 43
C. compiler error 
D. none of these



Answers

1. B 2. C 3. B 4. D 5. A 6. B 7. B 8. A 9. C 10. D 11. D 12. C 13. B 14. A 15. A

String Q & A

String Q-A



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
void ustrcpy(char *d, char *s);

int main()
{
   char name1[15] ="hello";
   char name2[15] ="ptinstitute.in";
   ustrcpy(name1, name2);
   printf("\n %s", name2);

   return 0;
}

void ustrcpy(char *d, char *s)
{
    d=s;
}
options:
A. ptinstitute.in
B. compiler error
C. runtime error
D. not print anything



Ques 2. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
void ustrcat(char d[], char s[]);

int main()
{
    char name1[15] = "good";
    char name2[15] ="ptinstitute.in";
    ustrcat(name1, name2);
    printf("\n %s", name1);
    return 0;
}

void ustrcat(char d[], char s[])
{
    int len1, len2,i;
    len1=strlen(d);
    len2=strlen(s);
    for(i=len1; i

Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char name1[] = {'g', 'o', 'o', 'd'};
    char name2[] ="ptinstitute.in";

    printf("\n %d %d", sizeof(name1), sizeof(name2));
    printf(" %d", sizeof(name1[1]));
    return 0;
}

options:
A. 5 15 1 
B. compiler error 
C. 5 14 3
D. 4 15 1


Ques 4. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
void ustrcpy(char *, char *);

int main()
{
    char name1[15];
    char name2[] ="ptinstitute.in";
    ustrcpy(name1, name2);
    printf("\n name1 = %s", name1);
    printf(" name2 = %s", name2);
    return 0;
}

void  ustrcpy(char *d, char *s)
{
    int i;
    for(i=0; i

Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char name1[] = {'g', 'o', 'o', 'd','j','k'};
    char name2[] ="ptinstitute.in";

    int ii[]={2,3,4,5,6,7,8};

    printf("\n %d %d", sizeof(name1), sizeof(name2));
    printf(" %d", sizeof(&name1));

    return 0;
}

options:
A. 7 15 4
B. compiler error 
C. 4 4 4
D. 6 15 4


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
char *str;
void fun(char *s);

int main()
{
    strcpy(str, "ptinstitute.in");
    fun(str);
    printf("\n %s",str);
    return 0;
}

void fun(char *s)
{
    printf(" %s",s);
}

options:
A. compiler error
B. runtime error
C. ptinstitute.in ptinstitute.in
D. ptinstitute.in


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun(char *s);
int main()
{
    char *s1 = "hello";
    char *s2= "good";

    while(s1!= s2)
    fun(s1);

    return 0;
}

void fun(char *s)
{
    printf("\n %s",s);
}

options:
A. compiler error
B. Infinite loop
C. hello
D. good


Ques 8. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s1 = "hello";
    char *s2 = "good";
    printf("\n %d", s2-s1);
    return 0;
}

options:
A. 6
B. 111
C. o
D. compiler error


Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";

    char *s2=s1;
    s2 =s2[1] -s2[3];
    printf("\n %s",s2);

    return 0;
}

options:
A. runtime error
B. compiler error
C. 2
D. lcome


Ques 10. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";

    printf("\n %s %s",&s1[1], &s2[2]);

    return 0;
}

options:
A. run time error
B. elcome lcome
C. compiler error
D. welcome welcome
  

Ques 11. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";
    printf("\n %c %c %c",*(s1+1), s1[2], 3[s1]);
    return 0;
}

options:
A. compiler error
B. e l c
C. runtime error
D. elcome lcome come


Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";
    printf("\n %s %s", s1+3, s1+s1[1]-s1[6]);
    return 0;
}


options:
A. welcome welcome
B. come welcome
C. compiler error
D. runtime error


Ques 13. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[1][1][2][4] = {'w', 'e', 'l', 'c', 'o', 'm', 'e', '

Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s1[1][1][2][4] = {'w', 'e', 'l', 'c', 'o', 'm', 'e', '\0'};
printf("\n %s ", ***s1);
return 0;
}
options:
A. welcome
B. compiler error
C. runtime error
D. welcom
'}; printf("\n %s ", ***s1); return 0; } options: A. welcome B. compiler error C. runtime error D. welcom

Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int i=0;
    int len;
    char *s1 = "welcome";
    char *p;

    p=(char *)malloc(10);
    len=strlen(s1);

    do{
        p[i] = s1[++i];
    }
    while(i

Ques 15. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

char * changecase(char *s2)
{
    char *t= (char *)malloc(15);
    int i;

    for(i=0; i<15; i++)
    {
        if(s2[i] >= 65 && s2[i]<97)
            t[i]=s2[i]+32;
        else
            t[i]=s2[i];
    }
    t[i]=0;
    return t;
}

int main()
{
    char *s1 = "PTINSTITUTE.IN";
    char *t=changecase(s1);
    printf("\n %s", t);
    return 0;
}

options:
A. PTINSTITUTE.IN
B. ptinstitute.in
C. compiler error
D. runtime error


Ques 16. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
void swap(int *p, int *q)
{
    int  t=*p;
    *p=*q;
    *q=t;
}

int main()
{
    int p=33, q=55;
    swap(&p,&q);

    printf("\n%d, %d", p, q);
    return 0;
}

options:
A. 33 55
B. 55 33
C. compiler error
D. runtime error



Answers

1. A 2. B 3. D 4. A 5. D 6. B 7. B 8. A 9. A 10. C 11. B 12. B 13. A 14. B 15. B 16. B

Structure and Union

Structure and Union


Ques 1. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

typedef struct str{
char * name[2]={"welcome", "good"};
int x=333;
float y=98.878;
char * name;
}p;

int main()
{
    p s1;

    printf("\n %s", s1.name[0]);
    printf(" %d", s1.x);

    return 0;
}

options:
A. welcome 333
B. good 333
C. Compile time error
D. ruin time error



Ques 2. what is the output for the following c program ?
#include <stdio.h>
#include <stdlib.h>

typedef struct str{
static int x;
float y;
}pstr;

int main()
{
    pstr p;
    p.x=32;
    p.y=22;
    printf("\n %d", p.x);
    printf("\n %f", p.y);

    return 0;
}

options:
A. compile time error
B. 32 22
C. run time error
D. 22 32


Ques 3. what is the output for the below program?

#include <stdio.h>
#include <stdlib.h>

union un{
int x;
float y =3434;
}uvar;

int main()
{
    uvar.x=0x33ff;

    printf("\n %x", uvar.x);
    printf("\n %f", uvar.y);

    return 0;
}

options:
A. 0x33ff, 3434
B. compile time error
C. 0x33ff 0.000
D. run time error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

union un{
int x;
char y ;
char z;
}uvar;

int main()
{
    uvar.x=0x3334;
    uvar.y = 'A';
    printf("\n %x", uvar.x);
    printf("\n %c", uvar.y);
    printf("\n %c", uvar.z);

    return 0;
}
options:
A. 0x3334 A,A
B. 0X0A0A A,A
C. 0X3341 95 95
D. 0X3341 A A 


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

union un{
int x;
char y ;
char z;
}uvar;

int main()
{
    printf("\n %d", sizeof(uvar));
    return 0;
}

options:
A. 6
B. 4
C. 8
D. 10


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
struct st{
    int y;
union un{
int x;
char m ;
char z;
}unvar;
};
int main()
{
    struct st svar;

    svar.unvar.x=0x1244;
    svar.y=0x4567;

    printf("\n 0x%x", svar.y);
    printf("\n 0x%x", svar.unvar.x);
    printf("\n %c", svar.unvar.m);
    printf("\n 0x%x", svar.unvar.z);
    return 0;
}

options:
A. compiler error
B. runtime error
C. 0x4567 0x4567 g 67
D. 0x4567 0x1244 D 0x44


Ques 7. what is the output ?
#include <stdio.h>
#include <stdlib.h>

struct st{
    int y;
union un{
int x;
char m ;
char z;
}unvar;
};
int main()
{
    struct st svar;

    printf("\n %d %d", sizeof(struct st), sizeof(union un));
    return 0;
}


options:
A. compile time error
B. 8 4
C. 8 6
D. 4 4


Ques 8. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

struct st{
    int y[4];
union un{
double x;
long m ;
char z[8];
}unvar;
};
int main()
{
    struct st svar;

 printf("\n 0x%x 0x%x", sizeof(struct st), sizeof(union un));

    return 0;
}
options:
A. compile time error
B. 0x18 0x18
C. 0x18 0x8
D. runtime error



Ques 9. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
typedef struct st {

    float average;
    struct st ptr;
}svar;
int main()
{
    svar sv;
    sv.average=99.44;
    sv.ptr=sv;
    printf("\n %f", sv.ptr.average);

    return 0;
}

options:
A. copile time error
B. run time error
C. 99.44
D. 99.00


Ques 10. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
typedef struct st {

    float average;
    char y;
}svar;
int main()
{
    svar s1, s2;
    s1.average=99.44;
    s2.average=99.44;
    if(s1==s2)
    printf("\n %d", s1.average);
    printf("\n struct var compare");
    return 0;
}

options:
A. 99
B. struct var compare
C. 99.44
D. compile time error


Ques 11. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
union un {

    char arr[4];
    int avg;
}u1;
int main()
{

    u1.avg=0;
    u1.arr[2]='F';
    u1.arr[3]='E';
    printf("\n %s", u1.arr);


    return 0;
}

options:
A. 0FE
B. nothing is printed
C. Compile time error
D. Garbage characters


Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
union un {

    char arr1[7];
    char arr2[7];    
}u1;
int main()
{
    strcpy(u1.arr1, "good");
    strcpy(u1.arr1, u1.arr2);
    u1.arr2[4]='b';
    printf("\n %s", u1.arr1);
    printf(" %s", u1.arr2);

    return 0;
}

options:
A. good goodb
B. compile time error
C. good bgood
D. run time error


Ques 13. If the system is little endian what is the output ?

#include <stdio.h>
#include <stdlib.h>

union un {

    char arr1[2];
    short svar;
}u1;
int main()
{
    u1.svar=0x4567;
    printf("\n 0x%x", u1.svar);
    printf(" 0x%x 0x%x", u1.arr1[0], u1.arr1[1]);

    return 0;
}


options:
A. 0x4567 0x67 0x45
B. 0x4567 0x45 0x67
C. runtime error
D. 0x4567 g E


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
union un {
    int x;
    short svar;
}u1;
int main()
{
    register int i=0;
    u1.x=0x4;
    u1.svar = 0x2;
    for(i=0; i<5; i++)
    u1.svar /= 0x2*i;
    printf("\n 0x%x", u1.svar);

    return 0;
}

options:
A. runtime error
B. compile time error
C. 0
D. 0.5


Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
struct st {

    int m,n,p;
}svar= {3, 5, 8};
int main()
{
    svar.m+=2;
    svar.n+=2;
    svar.p+=2;

    printf("\n %d %d %d ", svar.m, svar.n, svar.p);
    return 0;
}

options:
A. 3 5 8
B. runtime error
C. 5 7 10 
D. Compile error



Answers

1. C 2. A 3. B 4. D 5. B 6. D 7. B 8. C 9. C 10. D 11. B 12. A 13. A 14. A 15. C

Macro Pre-processor

Macro PreProcessor


Ques 1. what is the output for the below code?
#include <stdio.h>

#define min(x, y) x < y? x : y
int main()
{
    int x=2, y=33, z;
    z=min(x, y);

    printf("\n min= %d", z);
    return 0;
}

options:
A. 2
B. 33
C. compile time error
D. run time error



Ques 2. what is the output for the below code?

#include <stdio.h>

#define BIT

int main()
{
    #ifdef BIT
        printf("\n BIT ");
    #elif
        printf("\n BYTE);
    #else
        printf("\n word);
    #endif

    return 0;
}

options:
A. BIT
B. BYTE
C. word
D. compile time error


Ques 3. what is the output for the below code?
#include <stdio.h>

#define BYTE

#if BIT
    #define BIT 1
#else
    #define BYTE 8
#endif


int main()
{
    printf("\n BIT = %d" ,BIT);
    
    return 0;
}

options:
A. 1
B. 8
C. runtime error
D. Compile time error


Ques 4. what is the output for the below code?
#include <stdio.h>
#define xy(x,y) x##y

int main()
{
    printf("\n XY = %d" ,xy(2,3));
    return 0;
}


options:
A. 2
B. 3
C. 23
D. compile time error


Ques 5. what is the output for the below code?
#include <stdio.h>

#define M 3

#if M
    printf("\n ptinstitute.in");
#else
    printf("\n welcome");
#endif

int main()
{
    return 0;
}

options:
A. Compile time error
B. ptinstitute.in
C. welcome
D. run time error


Ques 6. what is the output for the below code?

#include <stdio.h>
#define MAX(a,b)  a>b?a:b

int main()
{
    int a=2,b=3,c=4,d=6,z;

    z=MAX(a+b, c+d);
    printf("\n z=%d",z);

    return 0;
}

options:
A. 5
B. 10
C. 4
D. 6


Ques 7. what is the output for the below code?
#include <stdio.h>

#define setbit(x,bitno)  x=(x | (1<<bitno))

int main()
{
    int a=0x3;

    setbit(a, 3);
    printf("\n a=%x",a);

    return 0;
}

options:
A. b
B. 11
C. 31
D. compile time error


Ques 8. what is the output ?
#include <stdio.h>

#define resetbit(x,bitno)  x=(x & ~(1<<bitno))

int main()
{
    int a=0x1f;

    resetbit(a, 2);
    printf("\n a=%x",a);

    return 0;
}
options:
A. compile time error
B. 2f
C. 1f
D. 1b



Ques 9. what is the output for the below code?
#include <stdio.h>
#define togglebit(x,bitno)  x=(x ^ (1<<bitno))

int main()
{
    int a=0x1b;

    togglebit(a, 2);
    printf("\n a=%x",a);

    return 0;
}

options:
A. 1c
B. 1b
C. 1f
D. 1d


Ques 10. what is the output for the below code?
#include <stdio.h>
#define cube(x) x*x*x

int main()
{
  int x=3;
  x = 9/cube(x);
  printf("%d", x);
  return 0;
}

options:
A. 0
B. 27
C. 0.333
D. compile time error


Ques 11. what is the output?

#include <stdio.h>
#define compute(x) x*x+3  x++
int main()
{
  int x=3;
  x = compute(x);
  printf("%d", x);
  return 0;
}

options:
A. 13
B. 12
C. Compile time error
D. run time error


Ques 12. what is the output?
#include <stdio.h>
# define getch  "%s Good morning "
int main()
{
   printf(getch, getch);
   return 0;
}

options:
A. %s Good morning %s Good morning 
B. run time error
C. Compile time error
D. %s Good morning Good morning 


Ques 13. what is the output for the below code?
#include <stdio.h>
#define ABC 10
#define ABC 22

int main()
{
  printf("%d ",ABC);
  #define ABC 33
  printf("%d ",ABC);

  return 0;
}

options:
A. Compile time error
B. 10 33
C. 22 33
D. run time error


Ques 14. what is the output for the below code?
#include <stdio.h>
#define len(len,gth) len##gth
int main()
{
   int length = 100, breadth=4,a;
   a=len(len, gth)* breadth;
   printf("%d", a);
   return 0;
}
options:
A. 400
B. compile time error
C. run time error
D. 25


Ques 15. what is the output for the below code?
#include <stdio.h>
#define abc(x,y) x+y * x-y
int main()
{
   int a;
   a=abc(3,4);
   printf("%d", a);
   return 0;
}

options:
A. 11
B. -7
C. -1
D. 17



Answers

1. A 2. A 3. C 4. C 5. A 6. B 7. A 8. D 9. C 10. B 11. C 12. D 13. C 14. A 15. A

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*