LearnFrenzy
Sign in Take a free test

Data Types · Find the Error · Question 8

Error (C17): bool used without <stdbool.h> Answer, explanation & discussion

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

Compiled as C17, why does this program fail?

main.c
#include <stdio.h>

int main(void) {
    bool ready = true;
    printf("%d\n", ready);
    return 0;
}
  • A bool must be capitalised
  • B printf cannot print a bool
  • C There is no bug
  • D Before C23, bool and true are macros from <stdbool.h>; without that header they are unknown Correct
Correct Answer: Option D

In C99–C17 the built-in type is _Bool; bool, true and false come from #include <stdbool.h>. In C23 they are keywords and this program compiles as it is.

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