Keywords and Identifiers in C Programming
Keywords
Keywords are predefined words that have a specific meaning and purpose. These words cannot be used as variable names, function names, or any other identifier names.
Below is the list of keywords in C:
Keyword | Description | Keyword | Description |
---|---|---|---|
auto | automatic storage duration | break | exit a loop or switch |
case | specify a case in a switch | char | character type |
const | constant value | continue | skip to the next iteration of a loop |
default | default case in a switch | do | execute a loop |
double | double precision floating point | else | conditional execution |
enum | enumeration type | extern | external variable or function |
float | single precision floating point | for | execute a loop |
goto | jump to a labeled statement | if | conditional execution |
int | integer type | long | long integer type |
register | register storage class | return | return from a function |
short | short integer type | signed | signed integer type |
sizeof | evaluate the size of a type or variable | static | static storage duration |
struct | structure type | switch | multiple selection |
typedef | define a new type name | union | union type |
unsigned | unsigned integer type | void | void type |
volatile | volatile type | while | execute a loop |
Identifiers
An identifier is a name used to identify a variable, function, or any other user-defined item. An identifier is a sequence of letters, digits, and underscores, and it must begin with a letter or an underscore.
Rules for defining identifiers
An identifier must start with a letter
(a to z or A to Z)
or an underscore(_)
.After the first character, an identifier can contain any combination of letters, digits
(0 to 9)
, andunderscores
.An identifier cannot be a keyword or a reserved identifier.
There is no limit to the length of an identifier, but most compilers have a maximum limit of around 31 characters.
An identifier can only contain ASCII characters.
Following are valid identifiers in C:
x
count
_temp
sum_of_numbers
The following are not valid identifiers in C because they do not start with a letter or an underscore:
1x (starts with a digit)
@count (starts with a special character)
temp! (ends with a special character)
It is a good programming practice to choose descriptive and meaningful names for identifiers to make the code easy to understand and maintain.