Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Wednesday, 28 January 2015

MCQ on C

What is the output of this C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         int x = i++, y = ++i;
  6.         printf("%d % d\n", x, y);
  7.         return 0;
  8.     }
a) 0, 2
b) 0, 1
c) 1, 2
d) Undefined

What is the output of this C code?
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 97;
  5.         int y = sizeof(x++);
  6.         printf("X is %d", x);
  7.     }
a) X is 97
b) X is 98
c) X is 99
d) Run time error

What is the output of this C code?
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 4, y, z;
  5.         y = --x;
  6.         z = x--;
  7.         printf("%d%d%d", x,  y, z);
  8.     }
a) 3 2 3
b) 2 3 3
c) 3 2 2
d) 2 3 4

What is the output of this C code?
  1.  #include <stdio.h>
  2.     void main()
  3.     {
  4.         int a = 5, b = -7, c = 0, d;
  5.         d = ++a && ++b || ++c;
  6.         printf("\n%d%d%d%d", a,  b, c, d);
  7.     }
a) 6 -6 0 0
b) 6 -5 0 1

c) -6 -6 0 1
d) 6 -6 0 1


. What is the output of this C code?
  1.  #include <stdio.h>
  2.     void main()
  3.     {
  4.         int a = -5;
  5.         int k = (a++, ++a);
  6.         printf("%d\n", k);
  7.     }
a) -4
b) -5
c) 4
d) -3

 What is the difference between the following 2 codes?
  1.     #include <stdio.h> //Program 1
  2.     int main()
  3.     {
  4.         int d, a = 1, b = 2;
  5.         d =  a++ + ++b;
  6.         printf("%d %d %d", d, a, b);
  7.     }
  1.     #include <stdio.h> //Program 2
  2.     int main()
  3.     {
  4.         int d, a = 1, b = 2;
  5.         d =  a++ +++b;
  6.         printf("%d %d %d", d, a, b);
  7.     }
a) No difference as space doesn’t make any difference, values of a, b, d are same in both the case
b) Space does make a difference, values of a, b, d are different
c) Program 1 has syntax error, program 2 is not
d) Program 2 has syntax error, program 1 is not



What is the output of this C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 1, b = 1, c;
  5.         c = a++ + b;
  6.         printf("%d, %d", a, b);
  7.     }
a) a = 1, b = 1
b) a = 2, b = 1
c) a = 1, b = 2
d) a = 2, b = 2

No comments:

Post a Comment