Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. 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

View Answer

Answer: d [Reason:] None.

2. 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("%dn", k);
  7.     }

a) -3
b) -5
c) 4
d) Undefined

View Answer

Answer: a [Reason:] None.

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 2;
  5.         x = x << 1;
  6.         printf("%dn", x);
  7.     }

a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine

View Answer

Answer: a [Reason:] None.

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         x = x >> 1;
  6.         printf("%dn", x);
  7.     }

a) 1
b) -1
c) 2 31 – 1 considering int to be 4 bytes
d) Either -1 or 1

View Answer

Answer: b [Reason:] None.

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         if (~0 == 1)
  5.             printf("yesn");
  6.         else
  7.             printf("non");
  8.     }

a) yes
b) no
c) compile time error
d) undefined

View Answer

Answer: b [Reason:] None.

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         if (!0 == 1)
  6.             printf("yesn");
  7.         else
  8.             printf("non");
  9.     }

a) yes
b) no
c) run time error
d) undefined

View Answer

Answer: a [Reason:] None.

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int y = 0;
  5.         if (1 |(y = 1))
  6.             printf("y is %dn", y);
  7.         else
  8.             printf("%dn", y);
  9.  
  10.     }

a) y is 1
b) 1
c) run time error
d) undefined

View Answer

Answer: a [Reason:] None.

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int y = 1;
  5.         if (y & (y = 2))
  6.             printf("true %dn", y);
  7.         else
  8.             printf("false %dn", y);
  9.  
  10.     }

a) true 2
b) false 2
c) either option a or option b
d) true 1

View Answer

Answer: c [Reason:] None.