LearnFrenzy
Sign in Take a free test

Operators and Expressions · Predict the Output · Question 12

C23: the type of a comparison result with auto Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following program, compiled as C23?

main.c
#include <stdio.h>

int main(void) {
    auto r = 3 > 2;
    bool b = 3 > 2;
    printf("%zu %zu %d\n", sizeof r, sizeof b, r + b);
    return 0;
}
  • A 4 1 2 Correct
  • B 1 1 2
  • C 4 4 2
  • D 1 1 1
Correct Answer: Option A

Even in C23, a comparison yields an int, so auto deduces int (4 bytes). Stored in a bool it becomes 1 byte. In r + b both are ints with value 1.

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