MCQ
Q.
Which of the following C++ statements correctly declares an integer variable named
score and initializes it with the value 100?
Correct Answer: A
The correct answer is int score = 100;.
🔑 Key Points
- In C++, to declare a variable, you must first specify its data type (e.g.,
intfor integer,floatfor floating-point,charfor character). - The variable name (identifier) follows the data type (e.g.,
score). Variable names must follow specific rules (start with a letter or underscore, no spaces, no keywords). - The assignment operator (
=) is used to give a value to a variable. - Every complete statement in C++ must end with a semicolon (
;).
📄 Additional Information
- Option B (
score int = 100;) is incorrect because the data type (int) must precede the variable name. - Option C (
integer score = 100;) is incorrect becauseintegeris not a valid C++ keyword for integer data type; the correct keyword isint. - Option D (
int score == 100;) is incorrect because==is the equality comparison operator, not the assignment operator. It checks if two values are equal, it does not assign a value. - Variables can be declared and initialized in separate steps (e.g.,
int score; score = 100;), but combining them as in option A is common and good practice.