Home
MCQS
C/C MCQ Quiz Hub
C Multiple Choice Questions C Operators
Choose a topic to test your knowledge and improve your C/C skills
1. What is the output of this C code? int main() { int i = -5; int k = i %4; printf("%d ", k); }
Compile time error
-1
1
None
2. What is the output of this C code? int main() { int i = 5; int l = i / -4; int k = i % -4; printf("%d %d ", l, k); return 0; }
Compile time error
-1 1
1 -1
Run time error
3. What is the output of this C code? int main() { int i = 7; i = i / 4; printf("%d ", i); return 0; }
Run time error
1
3
Compile time error
4. What is the value of x in this C code? void main() { int x = 4 *5 / 2 + 9; }
6.75
1.85
19
3
5. What is the output of this C code? void main() { int x = 4.3 % 2; printf("Value of x is %d", x); }
Value of x is 1.3
Value of x is 2
Value of x is 0.3
Compile time error
6. What is the output of this C code? void main() { int y = 3; int x = 7 % 4 * 3 / 2; printf("Value of x is %d", x); }
Value of x is 1
Value of x is 2
Value of x is 3
Compile time error
7. What is the output of this C code? void main() { int a = 5; int b = ++a + a++ + --a; printf("Value of b is %d", b); }
Value of x is 16
Value of x is 21
Value of x is 15
Undefined behaviour
8. The precedence of arithmetic operators is (from highest to lowest)?
%, *, /, +, -
%, +, /, *, -
+, -, %, *, /
%, +, -, *, /
9. Which of the following is not an arithmetic operation?
a *= 20;
a /= 30;
a %= 40;
a != 50;
10. Which of the following data type will throw an error on modulus operation(%)?
char
short
float
int
11. What is the output of this C code? int main() { int a = 20; double b = 15.6; int c; c = a + b; printf("%d", c); }
35
36
35.6
30
12. What is the output of this C code? int main() { int a = 20, b = 15, c = 5; int d; d = a == (b + c); printf("%d", d); } A. 1
1
40
10
5
13. What is the output of this C code? void main() { int x = 0; if (x = 0) printf("Its zero "); else printf("Its not zero "); }
ts not zero
Its zero
Run time error
None
14. What is the output of this C code? void main() { int k = 8; int x = 0 == 1 && k++; printf("%d%d ", x, k); }
0 9
0 8
1 9
1 8
15. What is the output of this C code? void main() { char a = 'a'; int x = (a % 10)++; printf("%d ", x); }
6
Junk value
Compile time error
7
16. What is the output of this C code? void main() { 1 < 2 ? return 1: return 2; }
returns 1
returns 2
varies
Compile time error
17. What is the output of this C code? void main() { unsigned int x = -5; printf("%d", x); }
Run time error
Varies
-5
5
18. What is the output of this C code? void main() { unsigned int x = -5; printf("%d", x); }
Run time error
Varies
-5
5
19. What is the output of this C code? int main() { int x = 2, y = 1; x *= x + y; printf("%d ", x); return 0; }
5
6
Undefined behaviour
Compile time error
20. What is the output of this C code? int main() { int x = 2, y = 2; x /= x / y; printf("%d ", x); return 0; }
2
1
0.5
Undefined behaviour
21. What is the type of the below assignment expression if x is of type float, y is of type int? y = x + y;
int
float
There is no type for an assignment expression
double
22. What is the value of the below assignment expression (x = foo())!= 1 considering foo() returns 2
2
True
1
0
23. Operation "a = a * b + a can also be written as:
a *= b + 1
(c = a * b)!=(a = c + a)
a = (b + 1)* a;
All of the mentioned
24. for c = 2, value of c after c <<= 1;
c = 1;
c = 2;
c = 3;
c = 4;
25. What is the output of this C code? int main() { int a = 1, b = 2; a += b -= a; printf("%d %d", a, b); }
1 1
1 2
2 1
2 2
26. What is the output of this C code? int main() { int a = 4, n, i, result = 0; scanf("%d", n); for (i = 0;i < n; i++) result += a; }
Addition of a and n
Subtraction of a and n.
Multiplication of a and n
Division of a and n.
27. Which of the following is an invalid assignment operator?
a %= 10;
a /= 10
a |= 10
None of the mentioned
28. What is the output of this C code? int main() { int c = 2 ^ 3; printf("%d ", c); }
1
8
9
0
29. What is the output of this C code? int main() { unsigned int a = 10; a = ~a; printf("%d ", a); }
-9
-10
-11
10
30. What is the output of this C code? int main() { if (7 & 8) printf("Honesty"); if ((~7 & 0x000f) == 8) printf("is the best policy "); }
Honesty is the best policy
Honesty
is the best policy
No output
31. What is the output of this C code? int main() { int a = 2; if (a >> 1) printf("%d ", a); }
0
1
2
No output
32. What is the output of this C code? int main() { int a = 2; if (a >> 1) printf("%d ", a); }
0
0
1
No output
33. Comment on the output of this C code? int main() { int i, n, a = 4; scanf("%d", &n); for (i = 0; i < n; i++) a = a * 2; }
Logical Shift left
No output
Arithmetic Shift right
bitwise exclusive OR
34. What is the output of this C code? void main() { int x = 97; int y = sizeof(x++); printf("x is %d", x); }
x is 97
x is 98
x is 99
Run time error
35. What is the output of this C code? void main() { int x = 4, y, z; y = --x; z = x--; printf("%d%d%d", x, y, z); }
3 2 3
2 2 3
3 2 2
2 3 3
36. What is the output of this C code? void main() { int x = 4; int *p = &x; int *k = p++; int r = p - k; printf("%d", r); }
4
8
1
Run time error
37. What is the output of this C code? void main() { int a = 5, b = -7, c = 0, d; d = ++a && ++b || ++c; printf(" %d%d%d%d", a, b, c, d); }
6 -6 0 0
6 -5 0 1
-6 -6 0 1
6 -6 0 1
38. What is the output of this C code? void main() { int a = -5; int k = (a++, ++a); printf("%d ", k); }
-3
-5
4
Undefined
39. What is the output of this C code? int main() { int x = 2; x = x << 1; printf("%d ", x);
4
1
Depends on the compiler
Depends on the endianness of the machine
40. What is the output of this C code? int main() { int x = -2; x = x >> 1; printf("%d ", x); }
1
-1
2 ^ 31 &quot;“ 1 considering int to be 4 bytes
Either (b) or (c)
41. What is the output of this C code? int main() { if (~0 == 1) printf("yes "); else printf("no "); }
Yes
No
Compile time error
undefined
42. What is the output of this C code? int main() { int x = -2; if (!0 == 1) printf("yes "); else printf("no "); }
Yes
No
Run time error
undefined
43. What is the output of this C code? int main() { int y = 0; if (1 |(y = 1)) printf("y is %d ", y); else printf("%d ", y); }
1
0
Run time error
undefined
44. What is the output of this C code? int main() { int y = 1; if (y & (y = 2)) printf("true %d "); else printf("false %d "); }
true 2
false 2
Either option a or option b
true 1
45. What is the difference between the following 2 codes? //Program 1 int main() { int d, a = 1, b = 2; d = a++ + ++b; printf("%d %d %d", d, a, b); } //Program 2 int main() { int d, a = 1, b = 2; d = a++ + ++b; printf("%d %d %d", d, a, b); }
No difference as space doesn&#039;t make any difference, values of a, b, d are same in both the case
No difference as space doesn&#039;t make any difference, values of a, b, d are different
Program 1 has syntax error, program 2 is not
Program 2 has syntax error, program 1 is not
46. What is the output of this C code? int main() { int a = 1, b = 1, c; c = a++ + b; printf("%d, %d", a, b); }
a = 1, b = 1
a = 2, b = 1
a = 1, b = 2
a = 2, b = 2
47. What is the output of this C code? int main() { int a = 1, b = 1, d = 1; printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++); }
15, 4, 5
9, 6, 9
9, 3, 5
6, 4, 6
48. For which of the following, "PI++; code will fail?
#define PI 3.14
char *PI = A&quot;;
float PI = 3.14;
Both (A) and (B)
49. What is the output of this C code? int main() { int a = 10, b = 10; if (a = 5) b--; printf("%d, %d", a, b--); }
a = 10, b = 9
a = 10, b = 8
a = 5, b = 9
a = 5, b = 8
50. What is the output of this C code? int main() { int i = 0; int j = i++ + i; printf("%d ", j); }
0
1
2
Compile time error
51. What is the output of this C code? int main() { int i = 2; int j = ++i + i; printf("%d ", j); }
6
5
4
Compile time error
52. Comment on the output of this C code? int main() { int i = 2; int i = i++ + i; printf("%d ", i); }
= operator is not a sequence point
++ operator may return value with or without side effects
it can be evaluated as (i++)+i or i+(++i)
Both a and b
53. What is the output of this C code? int main() { int i = 0; int x = i++, y = ++i; printf("%d % d ", x, y); return 0; }
0, 2
0, 1
1, 2
Undefined
54. What is the output of this C code? int main() { int i = 10; int *p = &i; printf("%d ", *p++); }
10
11
Garbage value
Address of i
55. What is the output of this C code? void main() { int x = 97; int y = sizeof(x++); printf("X is %d", x); }
X is 97
X is 94
X is 99
Run time error
56. What is the output of this C code? void main() { int x = 4, y, z; y = --x; z = x--; printf("%d%d%d", x, y, z); }
3 2 3
2 3 3
3 2 .3
2 3 4
57. What is the output of this C code? void main() { int x = 4; int *p = &x; int *k = p++; int r = p - k; printf("%d", r); }
48
8
1
Run time error
58. What is the output of this C code? void main() { int a = 5, b = -7, c = 0, d; d = ++a && ++b || ++c; printf(" %d%d%d%d", a, b, c, d); }
6 -6 0 0
6 -5 0 1
-6 -6 0 1
6 -6 0 1
59. What is the output of this C code? void main() { int a = -5; int k = (a++, ++a); printf("%d ", k); } A. -4B. -5C. 4D. -3
4
8
1
Run time error
60. What is the output of this C code? void main() { int x = 1, y = 0, z = 5; int a = x && y || z++; printf("%d", z); }
6
5
0
Varies
61. What is the output of this C code? void main() { int x = 1, y = 0, z = 5; int a = x && y && z++; printf("%d", z); }
6
5
0
Varies
62. What is the output of this C code? int main() { int x = 1, y = 0, z = 3; x > y ? printf("%d", z) : return z; }
3
1
Compile time error
Run time error
63. What is the output of this C code? void main() { int x = 1, z = 3; int y = x << 3; printf(" %d ", y); }
-2147483648
-1
Run time error
8
64. What is the output of this C code? void main() { int x = 0, y = 2, z = 3; int a = x & y | z; printf("%d", a); }
3
0
2
Run time error
65. What is the final value of j in the below code? int main() { int i = 0, j = 0; if (i && (j = i + 10)) //do something ; }
0
10
Depends on the compiler
Depends on language standard
66. What is the output of this C code? int main() { int i = 1; if (i++ && (i == 1)) printf("Yes "); else printf("No "); }
Yes
No
Depends on the compiler
Depends on the standard
67. Are logical operators sequence points?
True
False
Depends on the compiler
Depends on the standard
68. Does logical operators in C language are evaluated with short circuit?
True
False
Depends on the compiler
depends on the standard
69. Result of a logical or relational expression in C is?
True or False
0 or 1
0 if expression is false and any positive number if expression is true
None of the mentioned
70. What will be the value of d in the following program? int main() { int a = 10, b = 5, c = 5; int d; d = b + c == a; printf("%d", d); } A
Syntax error
1
5
10
71. What is the output of this C code? int main() { int a = 10, b = 5, c = 3; b != !a; c = !!a; printf("%d %d", b, c); }
5 1
0 3
5 3
1 1
72. Which among the following is NOT a logical or relational operator? A. !=B. ==C. ||D. = Which among the following is NOT a logical or relational operator?
!=
==
||
=
73. What is the output of this C code? int main() { int a = 10; if (a == a--) printf("TRUE 1 "); a = 10; if (a == --a) printf("TRUE 2 "); }
TRUE 1
TRUE 2
TRUE 1 TRUE 2
No output
74. Relational operators cannot be used on:
structure
long
strings
float
Submit