CPP Variable Naming Rules MCQ
Cpp MCQ- Home
- Tutorials
- Cpp
- Variable Naming Rules
- Multiple Choice Question
(1) One variable name can be declared with how many data types ?
A) One
B) Two
C) Three
D) Multiple
Explanation
In C++ one variable name can be declared only with single data type. If we declare it with more than one data type then compiler will generate an error.
(2) A well defined variable name should be.
A) Detailed
B) Explained
C) Descriptive
D) None
Explanation
A well defined variable name should be descriptive. Means this should also tells the programmer what kind of data is going to store in it. Variable name should not be very large or small but should be much descriptive.
(3) Which of the following is not allowed in between variable name ?
A) Alphabet
B) Number
C) Underscore
D) Space
Explanation
Space cannot be used in between variable name. Best practice is to use underscore in place of space if required.
(4) A variable name length can be upto _____ characters in C++
A) 21
B) 31
C) 41
D) 51
Explanation
Valid identifier name can be up to 31 characters in c++
(5) Which of the following is not allowed as first character of variable name in C++ ?
A) Alphabet
B) Space
C) Number
D) Underscroe
Explanation
Number cannot be used in start of variable name.
(6) Which of the following is valid variable name ?
A) speed
B) age
C) limit
D) All
Explanation
All of these are valid variable names according to identifier naming rules.
(7) Which of the folowing is not a valid variable name?
A) age
B) int
C) _rank
D) speed
Explanation
Data type cannot be used as variable name so that int is invalid.