LearnFrenzy
Sign in Take a free test

Decision Making · Predict the Output · Question 1

Logical operators with non-0/1 values – output Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int a = 3, b = 0;
    printf("%d %d %d %d\n", a && b, a || b, !a || b, !(a && !b));
    return 0;
}
  • A 0 1 0 0 Correct
  • B 0 3 0 1
  • C 0 1 1 0
  • D 3 3 0 0
Correct Answer: Option A

3 is true and 0 is false. a && b = 0, a || b = 1 (not 3), !a || b = 0 || 0 = 0, and !(a && !b) = !(1 && 1) = 0.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links