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

Multiple choice question for engineering

Set 1

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 0;
  5.         if (x = 0)
  6.             printf("Its zeron");
  7.         else
  8.             printf("Its not zeron");
  9.     }

a) Its not zero
b) Its zero
c) Run time error
d) None

View Answer

Answer: a

2. What is the output of this C code?

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

a) 0 9
b) 0 8
c) 1 8
d) 1 9

View Answer

Answer: b

3. What is the output of this C code?

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

a) 6
b) Junk value
c) Compile time error
d) 7

View Answer

Answer: c

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         1 < 2 ? return 1: return 2;
  5.     }

a) returns 1
b) returns 2
c) Varies
d) Compile time error

View Answer

Answer: d

5. What is the output of this C code?

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

a) Run time error
b) Aries
c) -5
d) 5

View Answer

Answer: c

6. What is the output of this C code?

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

a) 5
b) 6
c) Undefined behaviour
d) Compile time error

View Answer

Answer: b

7. What is the output of this C code?

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

a) 2
b) 1
c) 0.5
d) Undefined behaviour

View Answer

Answer: a

8. What is the output of this C code?

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

a) Compile time error
b) 1
c) 0
d) Undefined behaviour

View Answer

Answer: a

Set 2

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         void foo();
  5.         printf("1 ");
  6.         foo();
  7.     }
  8.     void foo()
  9.     {
  10.         printf("2 ");
  11.     }

a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler

View Answer

Answer: a

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         void foo(), f();
  5.         f();
  6.     }
  7.     void foo()
  8.     {
  9.         printf("2 ");
  10.     }
  11.     void f()
  12.     {
  13.         printf("1 ");
  14.         foo();
  15.     }

a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main

View Answer

Answer: b

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         void foo();
  5.         void f()
  6.         {
  7.             foo();
  8.         }
  9.         f();
  10.     }
  11.     void foo()
  12.     {
  13.         printf("2 ");
  14.     }

a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler

View Answer

Answer: d [Reason:] Even though the answer is 2, this code will compile fine only with gcc. GNU C supports nesting of functions in C as a language extension where as standard C compiler doesn’t.

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void foo();
  3.     int main()
  4.     {
  5.         void foo();
  6.         foo();
  7.         return 0;
  8.     }
  9.     void foo()
  10.     {
  11.         printf("2 ");
  12.     }

a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: b

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void foo();
  3.     int main()
  4.     {
  5.         void foo(int);
  6.         foo(1);
  7.         return 0;
  8.     }
  9.     void foo(int i)
  10.     {
  11.         printf("2 ");
  12.     }

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: a

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void foo();
  3.     int main()
  4.     {
  5.         void foo(int);
  6.         foo();
  7.         return 0;
  8.     }
  9.     void foo()
  10.     {
  11.         printf("2 ");
  12.     }

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: b

7. What is the output of this C code?

  1.     include <stdio.h>
  2.     void m()
  3.     {
  4.         printf("hi");
  5.     }
  6.     void main()
  7.     {
  8.         m();
  9.     }

a) hi
b) Run time error
c) Nothing
d) Varies

View Answer

Answer: a

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void m();
  3.     void n()
  4.     {
  5.         m();
  6.     }
  7.     void main()
  8.     {
  9.         void m()
  10.         {
  11.             printf("hi");
  12.         }
  13.     }

a) hi
b) Compile time error
c) Nothing
d) Varies

View Answer

Answer: b

Set 3

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = (y++) ? y == 1 && x : 0;
  6.         printf("%dn", z);
  7.         return 0;
  8.     }

a) 0
b) 1
c) Undefined behaviour
d) Compile time error

View Answer

Answer: a

2. What is the output of this C code?

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

a) Compile time error
b) Whatever character getchar function returns
c) Ascii value of character getchar function returns
d) 2

View Answer

Answer: c

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 1;
  5.         short int i = 2;
  6.         float f = 3;
  7.         if (sizeof((x == 2) ? f : i) == sizeof(float))
  8.             printf("floatn");
  9.         else if (sizeof((x == 2) ? f : i) == sizeof(short int))
  10.             printf("short intn");
  11.     }

a) float
b) short int
c) Undefined behaviour
d) Compile time error

View Answer

Answer: a

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 2;
  5.         int b = 0;
  6.         int y = (b == 0) ? a :(a > b) ? (b = 1): a;
  7.         printf("%dn", y);
  8.     }

a) Compile time error
b) 1
c) 2
d) Undefined behaviour

View Answer

Answer: c

5. What is the output of this C code?

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

a) 1
b) 2
c) Compile time error
d) Undefined behaviour

View Answer

Answer: a

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         int z = k < m ? k++ : m++;
  7.         printf("%d", z);
  8.     }

a) 7
b) 8
c) Run time error
d) None of the mentioned

View Answer

Answer: a

7. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         int z = k < m ? k = m : m++;
  7.         printf("%d", z);
  8.     }

a) Run time error
b) 7
c) 8
d) Depends on compiler

View Answer

Answer: b

8. The code snippet below produces

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         1 < 2 ? return 1 : return 2;
  5.     }

a) returns 1
b) returns 2
c) Varies
d) Compile time error

View Answer

Answer: d

Set 4

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 1, y = 0, z = 5;
  5.         int a = x && y || z++;
  6.         printf("%d", z);
  7.     }

a) 6
b) 5
c) 0
d) Varies

View Answer

Answer: a

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 1, y = 0, z = 5;
  5.         int a = x && y && z++;
  6.         printf("%d", z);
  7.     }

a) 6
b) 5
c) 0
d) Varies

View Answer

Answer: b

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 1, y = 0, z = 3;
  5.         x > y ? printf("%d", z) : return z;
  6.     }

a) 3
b) 1
c) Compile time error
d) Run time error

View Answer

Answer: c

4. What is the output of this C code?

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

a) -2147483648
b) -1
c) Run time error
d) 8

View Answer

Answer: d

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 0, y = 2, z = 3;
  5.         int a = x & y | z;
  6.         printf("%d", a);
  7.     }

a) 3
b) 0
c) 2
d) Run time error

View Answer

Answer: a

6. What is the final value of j in the below code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         if (i && (j = i + 10))
  6.             //do something
  7.             ;
  8.     }

a) 0
b) 10
c) Depends on the compiler
d) Depends on language standard

View Answer

Answer: a

7. What is the final value of j in the below code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 10, j = 0;
  5.         if (i || (j = i + 10))
  6.             //do something
  7.             ;
  8.     }

a) 0
b) 20
c) Compile time error
d) Depends on language standard

View Answer

Answer: a

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 1;
  5.         if (i++ && (i == 1))
  6.             printf("Yesn");
  7.         else
  8.             printf("Non");
  9.     }

a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: b

Set 5

1. What is the output of this C code(when 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%lf", &ch);
  7.         switch (ch)
  8.         {
  9.         case 1:
  10.             printf("1");
  11.             break;
  12.         case 2:
  13.             printf("2");
  14.             break;
  15.         }
  16.     }

a) Compile time error
b) 1
c) 2
d) Varies

View Answer

Answer: a

2. What is the output of this C code(When 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char *ch;
  5.         printf("enter a value btw 1 to 3:");
  6.         scanf("%s", ch);
  7.         switch (ch)
  8.         {
  9.         case "1":
  10.             printf("1");
  11.             break;
  12.         case "2":
  13.             printf("2");
  14.             break;
  15.         }
  16.     }

a) 1
b) Compile time error
c) 2
d) Run time error

View Answer

Answer: b

3. What is the output of this C code(When 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%d", &ch);
  7.         switch (ch)
  8.         {
  9.         case 1:
  10.             printf("1n");
  11.         default:
  12.             printf("2n");
  13.         }
  14.     }

a) 1
b) 2
c) 1 2
d) Run time error

View Answer

Answer: c

4. What is the output of this C code(When 2 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%d", &ch);
  7.         switch (ch)
  8.         {
  9.         case 1:
  10.             printf("1n");
  11.             break;
  12.             printf("hi");
  13.         default:
  14.             printf("2n");
  15.         }
  16.     }

a) 1
b) hi 2
c) Run time error
d) 2

View Answer

Answer: d

5. What is the output of this C code(When 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%d", &ch);
  7.         switch (ch, ch + 1)
  8.         {
  9.         case 1:
  10.             printf("1n");
  11.             break;
  12.         case 2:
  13.             printf("2");
  14.             break;
  15.         }
  16.     }

a) 1
b) 2
c) 3
d) Run time error

View Answer

Answer: b

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 1, b = 1;
  5.         switch (a)
  6.         {
  7.         case a*b:
  8.             printf("yes ");
  9.         case a-b:
  10.             printf("non");
  11.             break;
  12.         }
  13.     }

a) yes
b) no
c) Compile time error
d) yes no

View Answer

Answer: c

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 97;
  5.         switch (x)
  6.         {
  7.         case 'a':
  8.             printf("yes ");
  9.             break;
  10.         case 97:
  11.             printf("non");
  12.             break;
  13.         }
  14.     }

a) yes
b) yes no
c) Duplicate case value error
d) Character case value error

View Answer

Answer: c

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         float f = 1;
  5.         switch (f)
  6.         {
  7.         case 1.0:
  8.             printf("yesn");
  9.             break;
  10.         default:
  11.             printf("defaultn");
  12.         }
  13.     }

a) yes
b) yes default
c) Undefined behaviour
d) Compile time error

View Answer

Answer: d