Identifiers in C ++ Programming MCQ Questions and Answers
1. Which of the following is a valid identifier in C++?
A) 123name
B) name@cpp
C) _result
D) for
Answer: C) _result
2. In C++, identifiers can begin with which of the following characters?
A) A digit
B) A special character (#, $, @)
C) An underscore or an alphabet
D) A space
Answer: C) An underscore or an alphabet
3. Which of the following C++ identifiers is invalid?
A) student_name
B) int
C) _value2
D) number9
Answer: B) int
4. Identifiers in C++ are:
A) Case-insensitive
B) Keywords
C) Case-sensitive
D) Always in uppercase
Answer: C) Case-sensitive
5. Which identifier among the following is considered valid by the C++ compiler?
A) my-name
B) total%
C) MyName
D) new
Answer: C) MyName
6. The maximum length of an identifier in standard C++ is:
A) 8 characters
B) 16 characters
C) No fixed limit (implementation-defined)
D) 32 characters
Answer: C) No fixed limit (implementation-defined)
7. Which of the following cannot be used as an identifier name in C++?
A) sum1
B) average
C) total_value
D) switch
Answer: D) switch
8. The following identifier _tempVar in C++ is:
A) Invalid because it starts with _
B) Invalid because of capital letters
C) Valid identifier
D) Invalid because it uses mixed case
Answer: C) Valid identifier
9. In C++, identifiers are used to:
A) Define numeric constants
B) Name variables, functions, and classes
C) Mark the end of a statement
D) Represent keywords
Answer: B) Name variables, functions, and classes
10. Which of the following is an invalid identifier according to C++ rules?
A) result1
B) x2_y
C) 3data
D) data_3
Answer: C) 3data
11. Which of the following is a valid user-defined identifier in C++?
A) double
B) DoubleData
C) if
D) 7days
Answer: B) DoubleData
12. Which of the following symbols is allowed in C++ identifiers?
A) @
B) #
C) %
D) _ (underscore)
Answer: D) _ (underscore)
13. In C++, identifiers cannot contain:
A) Letters
B) Digits
C) Underscores
D) Spaces
Answer: D) Spaces
14. Which of the following variable names is valid in C++?
A) _
B) _xValue
C) -data
D) x!
Answer: B) _xValue
15. What is the rule for identifiers regarding case in C++?
A) They are case-sensitive
B) They are case-insensitive
C) Case depends on compiler
D) Case ignored during runtime
Answer: A) They are case-sensitive
16. Which of the following is a correct example of an identifier in C++?
A) value#
B) _number1
C) 9value
D) long double
Answer: B) _number1
17. Which of the following identifiers follow all naming rules in C++?
A) student age
B) class
C) 12price
D) _studentAge
Answer: D) _studentAge
18. Identifiers should be:
A) Reserved keywords
B) Meaningful and descriptive
C) Single characters only
D) Always capitalized
Answer: B) Meaningful and descriptive
19. Which of these identifiers would cause a compilation error in C++?
A) cost2
B) total_sum
C) new
D) StudentMarks
Answer: C) new
20. Which of the following is NOT allowed as a C++ identifier?
A) count_1
B) result
C) 5total
D) MAX_VALUE
Answer: C) 5total
21. Which is the correct statement about C++ identifiers?
A) They can contain letters, digits, and underscores.
B) They can begin with a number.
C) They can contain symbols like @ and $.
D) They are limited to 8 characters.
Answer: A) They can contain letters, digits, and underscores.
22. The identifier MyVariable and myvariable in C++ are:
A) Treated as same
B) Compiler-dependent
C) Different identifiers
D) Ignored by compiler
Answer: C) Different identifiers
23. The underscore _ in an identifier can appear:
A) At the beginning or middle
B) Only at the end
C) Only at the middle
D) Not at all
Answer: A) At the beginning or middle
24. Which of the following identifiers is invalid due to a naming rule violation?
A) __temp
B) data_2
C) total%sum
D) Amount
Answer: C) total%sum
25. Which of the following identifiers is best practice according to naming conventions in C++?
A) totalMarks
B) TOTALMARKS
C) total_marks
D) 1total
Answer: A) totalMarks
26. Which of the following identifiers is valid in C++?
A) first-name
B) first name
C) first_name
D) first@name
Answer: C) first_name
27. An identifier name in C++ should ideally:
A) Reflect the purpose of the variable or function
B) Be a single letter only
C) Contain spaces for clarity
D) Match a keyword name
Answer: A) Reflect the purpose of the variable or function
28. What is the valid identifier among these?
A) 99Bottles
B) Bottles99
C) bottles-99
D) bottles 99
Answer: B) Bottles99
29. Which of these is not allowed in a C++ identifier?
A) Digits
B) Uppercase letters
C) Underscores
D) Special characters like @, #, %
Answer: D) Special characters like @, #, %
30. A C++ identifier cannot start with:
A) An underscore
B) A number
C) A lowercase letter
D) An uppercase letter
Answer: B) A number
31. Which of the following is a valid identifier according to C++ naming conventions?
A) isValid
B) 4Valid
C) Valid!
D) is valid
Answer: A) isValid
32. Keywords like for, while, and if in C++:
A) Can be used as identifiers with a prefix
B) Can be redefined as identifiers
C) Cannot be used as identifiers
D) Can be used inside string literals only
Answer: C) Cannot be used as identifiers
33. Which of these names can represent a valid C++ variable?
A) while
B) name@cpp
C) student1
D) 2result
Answer: C) student1
34. In identifiers, which character separates multiple words most commonly in C++ convention?
A) – (dash)
B) . (dot)
C) _ (underscore)
D) : (colon)
Answer: C) _ (underscore)
35. Which of the following identifiers violates the rule of not beginning with a digit?
A) myName
B) 9count
C) _value
D) dataX
Answer: B) 9count
36. C++ identifiers can contain:
A) Letters, digits, underscores
B) Digits only
C) Symbols only
D) Alphabets only
Answer: A) Letters, digits, underscores
37. Which of these identifiers is invalid because it is a keyword?
A) Result
B) average_
C) return
D) avgValue
Answer: C) return
38. The identifier Total_Amount and total_amount are:
A) Same identifiers
B) Different identifiers
C) Synonyms
D) Treated as keywords
Answer: B) Different identifiers
39. Which identifier follows standard camelCase naming convention in C++?
A) studentName
B) student_name
C) STUDENTNAME
D) Student_Name
Answer: A) studentName
40. Which of the following is a syntactically valid C++ identifier?
A) max-value
B) new@
C) _maxValue
D) 7_max
Answer: C) _maxValue
41. C++ identifiers can be of:
A) Only lowercase letters
B) Only uppercase letters
C) Any combination of cases
D) Digits only
Answer: C) Any combination of cases
42. A valid identifier can contain digits but:
A) Only at the beginning
B) Not at the beginning
C) Must appear after underscore
D) Only even digits
Answer: B) Not at the beginning
43. Which identifier is valid and recommended as per naming best practices?
A) isEmpty
B) isempty
C) IsEmpty
D) ISEMPTY
Answer: A) isEmpty
44. Which of the following is not a valid identifier?
A) _temp
B) x1
C) if
D) ResultValue
Answer: C) if
45. What does a C++ compiler do when two identifiers differ only in case?
A) Treats them as same
B) Ignores both
C) Raises ambiguity error
D) Treats them as separate identifiers
Answer: D) Treats them as separate identifiers
46. Which of these identifiers will cause a compile-time error?
A) number
B) long
C) count5
D) totalSum
Answer: B) long
47. Which naming style is not recommended for identifiers in C++?
A) PascalCase for class names
B) camelCase for variables
C) Using all caps for regular variables
D) snake_case for constants
Answer: C) Using all caps for regular variables
48. An identifier that starts with two underscores (__) is:
A) User-defined only
B) Reserved for compiler implementation
C) Invalid in all cases
D) Used for macros only
Answer: B) Reserved for compiler implementation
49. The identifier _Main is:
A) Invalid in C++
B) Reserved keyword
C) Valid identifier
D) Forbidden for functions
Answer: C) Valid identifier
50. Which identifier name below is invalid due to the presence of a special character?
A) name#id
B) userName
C) ID123
D) _counter
Answer: A) name#id
51. Can identifiers in C++ contain Unicode characters?
A) No, never
B) Yes, in modern compilers (C++11 and later)
C) Only digits
D) Only ASCII letters
Answer: B) Yes, in modern compilers (C++11 and later)
52. Which identifier violates the rule of not using reserved names?
A) whileLoop
B) try
C) total_sum
D) myData
Answer: B) try
53. C++ distinguishes identifiers based on:
A) Letter case
B) White space
C) Location in program
D) Function scope only
Answer: A) Letter case
54. Which of the following variable names is valid?
A) data123
B) 123data
C) data@123
D) data 123
Answer: A) data123
55. The identifier main in C++:
A) Can be redefined for any function
B) Has a special meaning for program entry
C) Can’t be used at all
D) Is a keyword
Answer: B) Has a special meaning for program entry
56. Which of the following is not allowed in C++ identifiers?
A) Numbers
B) Blank spaces
C) Alphabets
D) Underscores
Answer: B) Blank spaces
57. Identifiers in C++ are formed according to rules defined by:
A) ISO Java Standard
B) ISO C++ Standard
C) ANSI C Standard
D) User preference
Answer: B) ISO C++ Standard
58. Which identifier below follows typical C++ constant naming style?
A) MAX_SIZE
B) MaxSize
C) max_size
D) maxSize
Answer: A) MAX_SIZE
59. Which of these identifiers is invalid due to the use of space?
A) my_total
B) total value
C) TotalValue
D) total_value
Answer: B) total value
60. What is true about identifier naming in C++?
A) Only lowercase allowed
B) Keywords can be reused
C) Names are case-sensitive
D) Compiler converts all to lowercase
Answer: C) Names are case-sensitive
61. Which of the following is a valid identifier name in C++?
A) my-name
B) 1result
C) _result1
D) break
Answer: C) _result1
62. What will happen if two identifiers differ only by underscore placement?
A) Treated as same
B) Causes syntax error
C) Treated as different identifiers
D) Depends on compiler
Answer: C) Treated as different identifiers
63. Which of the following cannot appear in the middle of an identifier?
A) A digit
B) An underscore
C) A space
D) A capital letter
Answer: C) A space
64. Which of these is a valid function name in C++?
A) 3sum
B) sum of
C) _sumOfNumbers
D) sum#total
Answer: C) _sumOfNumbers
65. An identifier in C++ must not conflict with:
A) File name
B) Header name
C) Reserved keywords
D) OS names
Answer: C) Reserved keywords
66. Which of these identifiers uses PascalCase style?
A) total_marks
B) totalMarks
C) TotalMarks
D) totalmarks
Answer: C) TotalMarks
67. Which of these is a bad naming practice for identifiers?
A) Using single letters for complex variables
B) Using descriptive names
C) Using camelCase
D) Using consistent style
Answer: A) Using single letters for complex variables
68. The identifier _1value is:
A) Invalid
B) Valid
C) Keyword
D) Reserved
Answer: B) Valid
69. Which identifier will the compiler reject?
A) _num
B) count1
C) do
D) Result2
Answer: C) do
70. In C++, identifiers can include:
A) Letters (A–Z, a–z), digits (0–9), and underscores
B) Any ASCII character
C) Special symbols
D) Whitespaces
Answer: A) Letters (A–Z, a–z), digits (0–9), and underscores
71. Which of these identifiers is valid for a global constant?
A) PI_VALUE
B) pi value
C) pi-value
D) 1pi
Answer: A) PI_VALUE
72. Identifiers are primarily used in C++ to:
A) Label and refer to program entities
B) Mark preprocessor directives
C) Replace keywords
D) Control memory
Answer: A) Label and refer to program entities
73. Which identifier follows typical C++ variable naming style?
A) totalAmount
B) Totalamount
C) TOTALAMOUNT
D) total_amount
Answer: A) totalAmount
74. Which of these is NOT an identifier?
A) a_variable
B) total1
C) 5value
D) result
Answer: C) 5value
75. Can identifiers in C++ contain hyphens (-)?
A) Yes
B) Only at the start
C) Only at the end
D) No
Answer: D) No
76. What does the following identifier represent?
MyClass
A) A macro
B) A keyword
C) A user-defined class name
D) A constant
Answer: C) A user-defined class name
77. Which of the following variable names is syntactically invalid?
A) X_1
B) X1
C) X1
D) X@1
Answer: D) X@1
78. Which identifier among these could represent a boolean variable?
A) integer
B) isValid
C) valueSum
D) Check123
Answer: B) isValid
79. Which identifier is invalid due to reserved keyword usage?
A) var_int
B) myFloat
C) float
D) floatValue
Answer: C) float
80. Which identifier is best used for a constant representing size?
A) max_size
B) MAX_SIZE
C) MaxSize
D) maxsize
Answer: B) MAX_SIZE
81. An identifier can’t start with a digit but may contain digits:
A) At any place after the first character
B) True
C) False
D) Only if preceded by underscore
Answer: B) True
82. Which of these identifiers is considered valid but discouraged?
A) __temp
B) tempValue
C) temp_value
D) valueTemp
Answer: A) __temp
83. Which of these names is best for a class according to C++ convention?
A) StudentRecord
B) studentRecord
C) student_record
D) studentrecord
Answer: A) StudentRecord
84. Which identifier would represent a private class member following common naming styles?
A) _count
B) count_
C) Count
D) COUNT
Answer: A) _count
85. Which of these identifiers cannot be used due to keyword conflict?
A) total
B) sum_
C) break
D) avg
Answer: C) break
86. The identifier data_2 is:
A) Invalid
B) Valid
C) Keyword
D) Reserved
Answer: B) Valid
87. Can a C++ identifier be the same as a library function name?
A) Yes, but not recommended
B) No, it’s forbidden
C) Only for global functions
D) Only inside main()
Answer: A) Yes, but not recommended
88. Which of these names would best represent a constant value in C++?
A) MAX_COUNT
B) MaxCount
C) maxCount
D) max_count
Answer: A) MAX_COUNT
89. Which identifier among the following is invalid?
A) TotalSum
B) total_sum
C) goto
D) totalSum
Answer: C) goto
90. The name _Value1 is:
A) Valid identifier
B) Invalid
C) Reserved keyword
D) Not allowed as per standard
Answer: A) Valid identifier
91. Which naming style is preferred for functions in C++?
A) camelCase
B) ALL_CAPS
C) snake_case
D) PascalCase
Answer: A) camelCase
92. Which of these is an invalid variable name?
A) id_number
B) total_sum
C) switch
D) name_2
Answer: C) switch
93. Can identifiers in C++ end with an underscore?
A) Yes
B) Yes, but not recommended
C) No
D) Only for constants
Answer: B) Yes, but not recommended
94. Which of the following identifiers is invalid due to containing a symbol?
A) count_1
B) count$1
C) count1
D) total_2
Answer: B) count$1
95. Identifiers like _MAX are usually reserved for:
A) System or compiler implementation
B) User-defined constants
C) Class members
D) Local variables
Answer: A) System or compiler implementation
96. What is the correct identifier for a loop counter?
A) 1count
B) count
C) count#
D) Count 1
Answer: B) count
97. Which of these identifiers violates naming convention, though it’s valid?
A) A
B) averageMarks
C) studentData
D) valueCount
Answer: A) A
98. Which of these names represents a descriptive identifier?
A) totalStudents
B) ts
C) t_s
D) std
Answer: A) totalStudents
99. The identifier _main_ in C++ is:
A) Keyword
B) Valid user-defined name
C) Compiler reserved
D) Invalid
Answer: B) Valid user-defined name
100. Which of the following rules applies to all identifiers in C++?
A) Can begin with any character
B) Can include space
C) Must begin with a letter or underscore
D) Must be lowercase only
Answer: C) Must begin with a letter or underscore
