Skip to content
Sign in
Computer PPSC

How do you declare an integer variable in C++?

Tap an option to check the answer. You can also press A–D.

Show answer

Correct answer: C) int x

C++ declarations follow the pattern "type name;", for example "int x;". "integer x;" is not valid C++, and "int 25;" is invalid syntax. Related facts: Other basic C++ types include float, char, double, and bool. A declaration can include initialization, for example "int x = 5;". Exam tip: Watch for the exact keyword "int" — "integer" is not a C++ keyword.
Explanation
C++ declarations follow the pattern "type name;", for example "int x;". "integer x;" is not valid C++, and "int 25;" is invalid syntax. Related facts: Other basic C++ types include float, char, double, and bool. A declaration can include initialization, for example "int x = 5;". Exam tip: Watch for the exact keyword "int" — "integer" is not a C++ keyword.