Following are the examples of some invalid variable names, Give reason and correct it
(a) 7PYPLOT
(b) On-line
(c) print
(d) one@two
Answers
Answer:
A C variable must begin with a letter (a-z or A-Z) or an underscore - and may be followed by any number of other letters (a-z or A-Z), numbers (0–9) and underscores. A C variable may NOT be one of the C reserved words (things like “if”, “switch”, “bool”, “float” and so on).
That said - EARLY versions of C allowed $ symbols in variable name too - I believe that was dropped from the specification in later versions, and you really SHOULDN’T use them - but I know that quite a few compilers (Microsofts being one of them) do actually allow them, sometimes with a special command-line option.
Some versions of C also allow other alphanumerics from extended characters sets - so, for example, it may be possible to write C variable names with accented letters or in cyrillic characters.
A few C compilers also impose limits on the length of a variable name. I believe Microsoft compilers will accept variables with names over 2048 characters - but will IGNORE everything after the 2048’th letter.
HOWEVER: Ignore all of those things! Stick with basic letters, numbers and underscores - do NOT use reserved words and keep your variable names with SANE lengths (let’s say under 40 characters). Break those rules (even if you can get away with it) and every C programmer on the planet will hate you for it!