How do you declare a boolean variable named 'done'?

Enhance your programming skills with the RECF Programming Test. Features flashcards and multiple choice questions with hints and explanations. Prepare for success!

Multiple Choice

How do you declare a boolean variable named 'done'?

Explanation:
Declaring a boolean variable in languages with a built-in boolean type uses the lowercase keyword bool, followed by the variable name and a semicolon. So the correct declaration is bool done;. This creates a variable named done that can hold true or false. In C, you’d need to include stdbool.h to use bool; without that header, bool isn’t defined. Other spellings like boolean, Bool, or BOOL use nonstandard or different language conventions, so they aren’t portable standard declarations. If you want to set an initial value at declaration, you can write bool done = false;.

Declaring a boolean variable in languages with a built-in boolean type uses the lowercase keyword bool, followed by the variable name and a semicolon. So the correct declaration is bool done;. This creates a variable named done that can hold true or false. In C, you’d need to include stdbool.h to use bool; without that header, bool isn’t defined. Other spellings like boolean, Bool, or BOOL use nonstandard or different language conventions, so they aren’t portable standard declarations. If you want to set an initial value at declaration, you can write bool done = false;.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy