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.         m();
  5.         void m()
  6.         {
  7.             printf("hi");
  8.         }
  9.     }

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

View Answer

Answer: b

2. What is the output of this C code?

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

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

View Answer

Answer: c

3. What is the output of this C code?

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

a) Run time error
b) hi
c) Infinite hi
d) hi hi

View Answer

Answer: d

4. Which of the following is a correct format for declaration of function?
a) return-type function-name(argument type);
b) return-type function-name(argument type)
{}
c) return-type (argument type)function-name;
d) all of the mentioned

View Answer

Answer: a

5. Which of the following function declaration is illegal?
a) int 1bhk(int);
b) int 1bhk(int a);
c) int 2bhk(int*, int []);
d) all of the mentioned

View Answer

Answer: d

6. Which function definition will run correctly?
a) int sum(int a, int b)
    return (a + b);
b) int sum(int a, int b)
    {return (a + b);}
c) int sum(a, b)
    return (a + b);
d) none of the mentioned

View Answer

Answer: b

7. Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ].
a) Yes, and we can use the function value conveniently
b) Yes, but we call the function again to get the value, not as convenient as in using variable
c) No, C does not support it
d) This case is compiler dependent

View Answer

Answer: c

8. The value obtained in the function is given back to main by using ________ keyword?
a) return
b) static
c) new
d) volatile

View Answer

Answer: a

Set 2

1. For each #if, #ifdef, and #ifndef directive.
a) There are zero or more #elif directives
b) Zero or one #else directive
c) One matching #endif directive
d) All of the mentioned

View Answer

Answer: d

2. The #else directive is used for
a) Conditionally include source text if the previous #if, #ifdef, #ifndef, or #elif test fails.
b) Conditionally include source text if a macro name is not defined
c) Conditionally include source text if a macro name is defined
d) Ending conditional text

View Answer

Answer: a

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #if MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %dn", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned

View Answer

Answer: b

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #ifdef MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %dn", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned

View Answer

Answer: a

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #if defined(MIN) + defined(MAX)
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %dn", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0

View Answer

Answer: a

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #if defined(MIN) - (!defined(MAX))
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %dn", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0

View Answer

Answer: b

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #ifdef(MIN)
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %dn", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Run time error
d) Preprocessor error

View Answer

Answer: d

8. What is the output of code given below?

  1.     #include <stdio.h>
  2.     #define MIN 0);
  3.     #ifdef MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %dn", MAX, MIN
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error due to illegal syntax for printf
c) Undefined behaviour
d) Compile time error due to illegal MIN value

View Answer

Answer: a

Set 3

1. Which keyword can be used for coming out of recursion?
a) break
b) return
c) exit
d) Both break and return

View Answer

Answer: b

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 0, i = 0, b;
  5.         for (i = 0;i < 5; i++)
  6.         {
  7.             a++;
  8.             continue;
  9.         }
  10.     }

a) 2
b) 3
c) 4
d) 5

View Answer

Answer: d

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 0, i = 0, b;
  5.         for (i = 0;i < 5; i++)
  6.         {
  7.             a++;
  8.             if (i == 3)
  9.                 break;
  10.         }
  11.     }

a) 1
b) 2
c) 3
d) 4

View Answer

Answer: d

4. The keyword ‘break’ cannot be simply used within:
a) do-while
b) if-else
c) for
d) while

View Answer

Answer: b

5. Which keyword is used to come out of a loop only for that iteration?
a) break
b) continue
c) return
d) none of the mentioned

View Answer

Answer: b

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0, j = 0;
  5.         for (i = 0;i < 5; i++)
  6.         {
  7.             for (j = 0;j < 4; j++)
  8.             {
  9.                 if (i > 1)
  10.                     break;
  11.             }
  12.             printf("Hi n");
  13.         }
  14.     }

a) Hi is printed 5 times
b) Hi is printed 9 times
c) Hi is printed 7 times
d) Hi is printed 4 times

View Answer

Answer: a

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         int j = 0;
  6.         for (i = 0;i < 5; i++)
  7.         {
  8.             for (j = 0;j < 4; j++)
  9.             {
  10.                 if (i > 1)
  11.                     continue;
  12.                     printf("Hi n");
  13.             }
  14.         }
  15.     }

a) Hi is printed 9 times
b) Hi is printed 8 times
c) Hi is printed 7 times
d) Hi is printed 6 times

View Answer

Answer: b

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         for (i = 0;i < 5; i++)
  6.             if (i < 4)
  7.             {
  8.                 printf("Hello");
  9.                 break;
  10.             }
  11.     }

a) Hello is printed 5 times
b) Hello is printed 4 times
c) Hello
d) Hello is printed 3 times

View Answer

Answer: c

Set 4

1. The following code ‘for(;;)’ represents an infinite loop. It can be terminated by.
a) break
b) exit(0)
c) abort()
d) all of the mentioned

View Answer

Answer: a

2. The correct syntax for running two variable for loop simultaneously is.
a) for (i = 0; i < n; i++)
     for (j = 0; j < n; j += 5)
b) for (i = 0, j = 0;i < n, j < n; i++, j += 5)
c) for (i = 0; i < n;i++){}
    for (j = 0; j < n;j += 5){}
d) None of the mentioned

View Answer

Answer: b

3. Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?
a) for (i = n; i>0; i–)
b) for (i = n; i >= 0; i–)
c) for (i = n-1; i>0; i–)
d) for (i = n-1; i>-1; i–)

View Answer

Answer: d

4. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3) ?
a) Variable
b) Function
c) typedef
d) macros

View Answer

Answer: d

5. What is the output of this C code?

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

a) The control won’t fall into the for loop
b) Numbers will be displayed until the signed limit of short and throw a runtime error
c) Numbers will be displayed until the signed limit of short and program will successfully     terminate
d) This program will get into an infinite loop and keep printing numbers with no errors

View Answer

Answer: c

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k)
  6.             printf("Hello");
  7.     }

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

View Answer

Answer: a

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k < 3; k++)
  6.         printf("Hello");
  7.     }

a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies

View Answer

Answer: a

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double k = 0;
  5.         for (k = 0.0; k < 3.0; k++)
  6.             printf("Hello");
  7.     }

a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely

View Answer

Answer: b

Set 5

1. What is the output of this C code?

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

a) 1 2 3 4 5
b) 1 2 3 4
c) Compile time error
d) Stack overflow

View Answer

Answer: d

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void reverse(int i);
  3.     int main()
  4.     {
  5.         reverse(1);
  6.     }
  7.     void reverse(int i)
  8.     {
  9.         if (i > 5)
  10.             return ;
  11.         printf("%d ", i);
  12.         return reverse((i++, i));
  13.     }

a) 1 2 3 4 5
b) Segmentation fault
c) Compilation error
d) Undefined behaviour

View Answer

Answer: a

3. In expression i = g() + f(), first function called depends on
a) Compiler
b) Associativiy of () operator
c) Precedence of () and + operator
d) Left to write of the expression

View Answer

Answer: a [Reason:] None.

4. What is the value of i and j in the below code?

  1.     #include <stdio.h>
  2.     int x = 0;
  3.     int main()
  4.     {
  5.         int i = (f() + g()) || g();
  6.         int j = g() || (f() + g());
  7.     }
  8.     int f()
  9.     {
  10.         if (x == 0)
  11.             return x + 1;
  12.         else
  13.             return x - 1;
  14.     }
  15.     int g()
  16.     {
  17.         return x++;
  18.     }

a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined

View Answer

Answer: d

5. What is the value of i and j in the below code?

  1.     #include <stdio.h>
  2.     int x = 0;
  3.     int main()
  4.     {
  5.         int i = (f() + g()) | g(); //bitwise or
  6.         int j = g() | (f() + g()); //bitwise or
  7.     }
  8.     int f()
  9.     {
  10.         if (x == 0)
  11.             return x + 1;
  12.         else
  13.             return x - 1;
  14.     }
  15.     int g()
  16.     {
  17.         return x++;
  18.     }

a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined

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 = 0;
  5.         int z = y && (y |= 10);
  6.         printf("%dn", z);
  7.         return 0;
  8.     }

a) 1
b) 0
c) Undefined behaviour due to order of evaluation
d) 2

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 = 0;
  5.         int z = (y++) ? 2 : y == 1 && x;
  6.         printf("%dn", z);
  7.         return 0;
  8.     }

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

View Answer

Answer: b

8. 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;
  6.         z = (y++, y);
  7.         printf("%dn", z);
  8.         return 0;
  9.     }

a) 0
b) 1
c) Undefined behaviour
d) Compilation error

View Answer

Answer: b

9. What is the output of this C code?

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

a) 0
b) 1
c) Undefined behaviour due to order of evaluation can be different
d) Compilation error

View Answer

Answer: b

10. What is the output of this C code?

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

a) 12
b) 20
c) 4
d) Either 12 or 20

View Answer

Answer: b