Multiple Choice Questions and Answers for Relational & Logical Operators in C Language

These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Relational & Logical Operators” along with answers, explanations and/or solutions:

1. What is the output of this C code?
  1.     #include 
  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
Answer:a
2. What is the output of this C code?
  1.     #include 
  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
Answer:b
3. What is the output of this C code?
  1.     #include 
  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
Answer:c
4. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 1, z = 3;
  5.         int y = x << 3;
  6.         printf(" %d\n", y);
  7.     }
a) -2147483648
b) -1
c) Run time error
d) 8
Answer:d
5. What is the output of this C code?
  1.     #include 
  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
Answer:a
6. What is the final value of j in the below code?
  1.     #include 
  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
Answer:a
7. What is the final value of j in the below code?
  1.     #include 
  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
Answer:a
8. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 1;
  5.         if (i++ && (i == 1))
  6.             printf("Yes\n");
  7.         else
  8.             printf("No\n");
  9.     }
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
Answer:b
9. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 3;
  5.         int b = ++a + a++ + --a;
  6.         printf("Value of b is %d", b);
  7.     }
a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
Answer:d 
10. The precedence of arithmetic operators is (from highest to lowest)

a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
Answer:a 
11. Which of the following is not an arithmetic operation?

a) a *= 10;
b) a /= 10;
c) a != 10;
d) a %= 10;
Answer:c 
12. Which of the following data type will throw an error on modulus operation(%)?

a) char
b) short
c) int
d) float
Answer:d 
13. Which among the following are the fundamental arithmetic operators, ie, performing the desired operation can be done using that operator only?

a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
Answer:a 
14. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 10;
  5.         double b = 5.6;
  6.         int c;
  7.         c = a + b;
  8.         printf("%d", c);
  9.     }
a) 15
b) 16
c) 15.6
d) 10
Answer:a 
15. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 10, b = 5, c = 5;
  5.         int d;
  6.         d = a == (b + c);
  7.         printf("%d", d);
  8.     }
a) Syntax error
b) 1
c) 10
d) 5
Answer: b

Related

Multiple Choice Questions 162702679684203625

Post a Comment

emo-but-icon

item