Keywords and Identifiers
Keywords in C are reserved words that have special meanings. They cannot be used as identifiers. Some examples of keywords include:
Category | Keywords |
---|---|
Data Types | int, float, char, double, void |
Control Flow | if, else, switch, case, for, while, do |
Storage Classes | auto, extern, static, register |
Modifiers | short, long, signed, unsigned |
Others | return, break, continue, sizeof, typedef, struct, enum, union, const, volatile, default, goto |
Identifiers are the building blocks of a program. Identifiers are unique names that are assigned to variables, structs, functions, and other entities. They are used to uniquely identify the entity within the program.
Rules for Defining Identifiers:
- They must begin with a letter or underscore, followed by letters, digits, or underscores.
- It should not be a keyword.
- It must not contain white space.
- They must begin with a letter or underscore, followed by letters, digits, or underscores.
Code Example: Using Keywords and Identifiers
#include <stdio.h>
int main() {
int myNumber = 10; // myNumber as an Identifier
if (myNumber > 0) { // if as Keyword
printf("Positive Number");
}
return 0;
}
Output
Positive Number