Question 8
Back to Exercise
Compiled as C23, why is this program rejected?
#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!