C Programming Questions and Answers – Relational & Logical Operators – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Relational & Logical Operators – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. What will be the output of the following 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
Explanation: None.
advertisement
advertisement

2. What will be the output of the following C code?

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  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
Explanation: None.
advertisement

3. What will be the output of the following 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
Explanation: None.
advertisement

4. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: d
Explanation: None.

5. What will be the output of the following 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
Explanation: None.

6. What will be the final value of j in the following C 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
Explanation: None.

7. What will be the final value of j in the following C 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
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.