Keywords in C Programming Language: A Comprehensive Guide
Table of Content:
C programs are constructed from a set of reserved words which provide control and from libraries which perform special functions. The basic instructions are built up using a reserved set of words, such as main, for, if, while, default, double, extern, for, and int, etc., C demands that they are used only for giving commands or making statements. You cannot use a default, for example, as the name of a variable. An attempt to do so will result in a compilation error.
Restrictions apply to keywords
- Keywords are the words whose meaning has already been explained to the C compiler and their meanings cannot be changed.
- Keywords can be used only for their intended purpose.
- Keywords cannot be used as user-defined variables.
- All keywords must be written in lowercase.
Keywords have standard, predefined meanings in C. These keywords can be used only for their intended purpose; they cannot be used as programmer-defined identifiers. Keywords are an essential part of a language definition. They implement specific features of the language. Every C word is classified as either a keyword or an identifier. A keyword is a sequence of characters that the C compiler readily accepts and recognizes while being used in a program. Note that the keywords are all lowercase. Since uppercase and lowercase characters are not equivalent, it is possible to utilize an uppercase keyword as an identifier.
32 Keywords in C Programming Language
| 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 |
Keyword Types
| Keyword Types | Keywords |
| Data types |
int char float double |
| Qualifiers |
signed unsigned short long |
| User-defined |
typedef Enum |
| Storage Classes |
auto register static extern |
| Loop |
For While Do |
| Decision |
if else switch case default |
| Jump |
Break continue Goto |
| Derived |
struct union |
| function |
void return |
| Others |
const volatile sizeof |
Data types
| int | Specifies the integer type of value a variable will hold |
| char | Specifies the character type of value a variable will hold |
| float | Specifies the single-precision floating-point of value a variable will hold |
| double | Specifies the double-precision floating-point type of value a variable will |
Qualifiers
| signed | Specifies a variable can hold positive and negative integer type of data |
| unsigned | Specifies a variable can hold only the positive integer type of data |
| short | Specifies a variable can hold fairly small integer type of data |
| long | Specifies a variable can hold fairly large integer type of data |
User-defined
| typedef | Used to define a new name for an existing data type |
| Enum | Gives an opportunity to invent own data type and define what values the variable of this data type can take |
Loop
| For | Loop is used when the number of passes is known in advance |
| While | Loop is used when the number of passes is not known in advance |
| Do | Loop is used to handle menu-driven programs |
Decision
Jump
| Break | Used to force immediate termination of a loop, bypassing the conditional expression and any remaining code in the body of the loop |
| continue | Used to take the control to the beginning of the loop bypassing the statements inside the loop |
| Goto | Used to take the control to required place in the program |
Storage Classes
| Storage Classes | Storage | Default initial value | Scope | Life |
|
auto |
Memory | An unpredictable value | Local | Till the control remains within the block |
| register | CPU registers | Garbage value | Local | Till the control remains within the block |
| static | Memory | Zero | Local | Value of the variable persists between different function calls |
| extern | Memory | Zero | Global | Till the program's execution doesn't come to an end |
Remember: Some Important points
- The keywords are also called ‘Reserved words’.
- Keywords are the words whose meaning has already been explained to the C compiler and their meanings cannot be changed.
- Keywords serve as basic building blocks for program statements.
- Keywords can be used only for their intended purpose.
- Keywords cannot be used as user-defined variables.
- All keywords must be written in lowercase.
- 32 keywords available in C.
- Question 1: What is the purpose of the keyword typedef?
- Question 2: List out some keywords available in C language.
- Question 3: What is keyword in C?
- Question 4: What is Standard Header Files ?
- Question 5: When is the "void" keyword used in a function?
- Question 6: Which key word is used to perform unconditional branching?
- Question 7: What are the valid places for the keyword break to appear.
- Question 8: What is a static identifier?
- Question 9: What is volatile keyword?
- Question 10: What is keyword auto for?
- Question 11: What is the maximum length of an identifier?