Which of the following are invalid variables names in c and why | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Which of the following are invalid variables names in c and why

a) #HASH b)Total% c)Variable name d)WHILE e)_main() f)Salary g)$hello h)1st

28th Aug 2019, 3:36 AM
Naveen Shah
Naveen Shah - avatar
5 Answers
+ 4
As listed in the C tutorial: "... The name of a variable (also called the identifier) must begin with either a letter or an underscore and can be composed of letters, digits, and the underscore character... " In other words, a variable cannot begin with anything which is not an underscore or an alphabetical character. A variable cannot contain anything which is not an underscore, an alphabetical character or a numeric character.
28th Aug 2019, 3:44 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
So which of these is invalid variable and reason for that
28th Aug 2019, 4:03 AM
Naveen Shah
Naveen Shah - avatar
+ 3
Naveen Shah Well, do you have any guesses? If you can tell us your answer and your perspectives as to why those are your answers, we can correct you if necessary. From the rules I quoted, the answers should be obvious.
28th Aug 2019, 5:13 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
g) will be valid in PHP but not C.
28th Aug 2019, 7:42 AM
Sonic
Sonic - avatar
+ 1
Which of the following are invalid names and why ? Row2, Minimum, float, Customer Name,&Rollno,First_Name,A$
22nd Nov 2020, 4:14 AM
Siddarth
 Siddarth - avatar