LearnFrenzy
Sign in Take a free test

C Variables · Find the Error · Question 8

Error (C23): auto without an initializer Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

Compiled as C23, why is this program rejected?

main.c
#include <stdio.h>

int main(void) {
    auto value;
    value = 42;
    printf("%d\n", value);
    return 0;
}
  • A 42 is not a valid value
  • B Type inference needs an initializer: auto value = 42; – there is nothing to deduce the type from Correct
  • C auto is not a C keyword
  • D There is no bug
Correct Answer: Option B

C23's auto deduces the type from the initializer in the same declaration. Without one there is no type (and implicit int was removed in C99). Write auto value = 42; or simply int value;.

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