LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Predict the Output · Question 12

C23 constexpr, auto and typeof together – output 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) {
    constexpr int SIZE = 4;
    auto half = SIZE / 2.0;
    typeof(half) twice = half * 2;
    printf("%.1f %zu %.1f\n", half, sizeof twice, twice);
    return 0;
}
  • A 2.0 8 4.0 Correct
  • B 2.0 4 4.0
  • C 2 8 4
  • D Compilation error
Correct Answer: Option A

SIZE / 2.0 is a double, so auto deduces double, and typeof(half) is double too (8 bytes).

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