What are Keywords in C:
Keywords are words with a special meaning to the compiler. We can’t use the keywords for anything in a C program. If you try to do, the C compiler will throw an error.
In this post, we will learn what are keywords and what type of error is thrown by the compiler if we try to use them.
Restrictions on Keywords:
The meaning of Keywords is already explained to the compiler. So, if you try to use any of the keyword as an identifier, the compiler will throw an error. It will not compile the program.
These words can be used only for their purpose. You will find keywords in other programming languages as well and the same rule applies in all other languages, i.e. you can’t use these for any other purpose.
In C, all keywords are written in lowercase and these are also called reserved words.
List of keywords in C:
There are total 32 keywords allowed in ANSI C. Following are these keywords:
int | float | char | double |
long | short | signed | unsigned |
auto | register | extern | static |
enum | for | do | while |
struct | union | if | else |
volatile | sizeof | const | goto |
continue | break | void | return |
switch | case | default | typeof |
Example program with keyword:
Let’s take an example of C program with different keywords:
#include <stdio.h>
int main()
{
int n;
char c;
return 0;
}
In this program, there are three keywords we are using: int, char and return.
This program will work. Because we are creating an int variable, a char variable and the main method returns an integer.
Now, let’s try to create an integer of name char and a character of name int.
#include <stdio.h>
int main()
{
int char;
char int;
return 0;
}
It will throw errors:
We can’t use the keywords for anything else.
You might also like:
- How to create a hollow diamond star pattern in C
- C program to print the size of the longest word in a string
- How to print the longest word of a string in C
- C program to convert binary values to octal
- C program to check if a number is Neon or not
- C program to check if a number is a Strong number or not
- C program to keep reading inputs until -1 is received
- 4 different C program to check if a number is Armstrong number or not