Just as English words are built from letters, C programs are built from a fixed set of characters, which form names and keywords. This section covers the character set, the rules for naming things in C, and the words C reserves for itself.
The C character set
The character set is the collection of characters that may appear in C source code:
space, tab, newline (separate words; otherwise ignored by the compiler)
Identifiers
Rules for forming an identifier:
It may contain only letters, digits and the underscore _.
The first character must be a letter or an underscore, not a digit.
Upper and lower case are different: total, Total and TOTAL are three different names.
No spaces or other special characters are allowed.
It must not be a keyword.
Compilers must distinguish at least the first 31 characters (63 since C99) of an internal name, so very long names that differ only near the end are risky.
Valid
Invalid
Reason
total
2nd_value
Starts with a digit
tax_rate
order-no
Hyphen not allowed
_count
error flag
Space not allowed
X123
"name"
Quotes not allowed
student_1
int
Keyword
Keywords
A keyword is a reserved word with a fixed meaning in C. It cannot be used as an identifier. ANSI C (C89) has 32 keywords, all in lower case:
auto
double
int
struct
break
else
long
switch
case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue
for
signed
void
default
goto
sizeof
volatile
do
if
static
while
Later standards added more, such as inline, restrict and _Bool (C99).
Key takeaways
C source code uses letters, digits, special characters and whitespace.
Identifiers: letters, digits and underscore; not starting with a digit; case-sensitive; not a keyword.
C89 has 32 lower-case keywords; library function names are not keywords.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain why max value, max-value and 2max are invalid identifiers, and correct each one.
Show worked answer
max value contains a space, which separates words, so C sees two names; correct it to max_value. max-value contains a hyphen, which C reads as the subtraction operator (max minus value); correct it to max_value. 2max starts with a digit, which is not allowed for the first character; correct it to max2 or max_2.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-types-operators-and-expressions/character-set-identifiers-and-keywords/ to read this page.