Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Valid Variable Names Given the following variable names, circle either valid or

ID: 3788901 • Letter: V

Question

Valid Variable Names Given the following variable names, circle either valid or invalid, indicating if the variable name is valid or invalid. Ifa variable name is invalid, explain why. 1. numl Valid Invalid 2. first Namel Valid Invalid Reason Invalid because you can't have a space in a variable. 3. lastName Valid Invalid Reason Valid 4. phoned Valid Invalid Reason Invalid because you can't have any special characters. 5. TOTAL Valid Invalid Reason Valid 6. Average Valid Invalid Reason 7. Avg Valid Invalid Reason 8. final grade Valid Invalid Reason 9, Home Address valid Invalid Reason 10. code? value Valid Invalid Reason

Explanation / Answer


The rules in C++ for identifiers are :

   - Only Alphabets,Digits and Underscores are permitted.
   - Identifier name cannot start with a digit.
   - Key words cannot be used as a name.
   - Upper case and lower case letters are distinct.
   - Special Characters are not allowed
   - Global Identifier cannot be used as "Identifier".
1.
   num1 => valid
2.
   Not valid => space is not allowed

3. valid
4. not valid => # is not allowed
5. valid
6. valid
7. valid
8. valid
9. valid
10. Not valid => ? is not allowed
11. Not valid => $ is not allowed
12. Not valid => $ is not allowed
13. valid
14. not valid => space is not allowed
15. not valid => can not start with ! and ! is not allowed
16. not valid => ! is not allowed
17. valid