Rules for identifiers in C

  1. The first character must be an alphabet or underscore.
  2. Must consist of only letters, digits, or underscore.
  3. Only the first 31 characters are significant.
  4. Cannot use a keyword.
  5. Must not contain white space.

Example:

 
Variable name Valid/Invalid Why?
abc Valid No rules were violated.
XYZ Valid No rules were violated.
1st Invalid The first character is a digit. (Violated 1st rule)
_health Valid No rules were violated.
#dontspoiltheendgame Invalid Starts with the special symbol.(Violated 1st & 2nd rule).
max number Invalid Contains whitespace. (Violated 5th rule)
max_number Valid No rules were violated.
float Invalid Makes use of a reserved keyword. (Violated 4th rule)
Price$1 Invalid Contains a special symbol. (Violated 2nd rule)
Number#1 Invalid Contains a special symbol. (Violated 2nd rule)
Number_1 Valid No rules were violated.

Comments

Popular posts from this blog

C program to read and display book information using structure

Count positive, negative and zero values in an array

Maximum value from array