Welcome back guys, feeling excited, so in this module, we are going to talk about the Keywords in C Programming, till now we have covered the variables and constants, data types in C, if you didn’t know about these terms, my recommendation is to first refer that module then go through this, then only you can grasp about how the things are been done.
Let’s move into the details of this lecture:
Keywords in C Programming
We talked about variables and know that it’s something we can change the value of as per our requirements, similarly, keywords are something that has their own meanings. It is pre-defined by the C library. One can’t use the keywords as a variable name or for defining something else. These are also known as reserved words that have special meanings to the compiler. They become an important part of the syntax and play an important role in structuring a program. Keywords in C Programming can not be used as an identifier.
Let’s take an example for Keywords in C Programming:
int age = 20;
Here, in the above example, int is the keyword and age is the variable name, which is holding a value of 20 in it. So, it is clear that you can’t declare the keyword as the variable name, it will throw an error.
List of 32 Keywords in C Programming
There are a total of 32 keywords available in C programming. Let’s see them.
auto | continue | default | if |
const | break | case | static |
Float | for | goto | return |
double | else | enum | while |
unsigned | switch | sizeof | union |
struct | signed | typedef | extern |
short | void | volatile | char |
int | long | register | do |
This is the total list of keywords available in the C programming library. Let’s see some of them in detail with their meanings.
auto keyword in C programming: It declares an automatic variable. Example
auto int num1;
Here, this statement in the above example simply suggests that num1 is the variable declared under storage class auto and of type int, i.e., can hold only integer values in it.
Any variables declared under any function body are automatic by default. Whenever the functions are executed, they are recreated each and every time.
break and continue keyword in C programming: It is used with any loops or switch-case statements which are conditional statements, which will see in the coming modules, but generally break keyword is used to terminate some action and come out of that particular block, whereas continue keyword is used to continue with the particular statement then and there.
void keyword in C programming: It is a return type, which indicates that no value is to be returned i..e, null value.
goto keyword in C programming: It is used as a jump statement as it takes you from one part of the program to another part.
enum keyword in C programming: indicates the set of constants.
sizeof keyword in C programming: tells the size of a particular variable.
for, while, do keyword in C programming: These are the types of loops present in C Programming, used to perform different actions.
union keyword in C programming: It represents the collection of the variables, which have the same memory storage and location.
if, else, switch, case, default keyword in C programming: These are the conditional statements, used for making decisions for controlling the structure of the program.
These are some of the keywords with their respective meanings, we will cover each keyword in detail in their respective sections, as of now we should only need to know this much.
What is an Identifier in C Programming?
Identifier refers to the name which you give to define entities such as variables, structures, classes, functions, etc.
It should be unique, while creating or defining a particular variable name, it should be given a unique name so that it can easily be identifiable for which purpose this particular variable is defined. For example:
int age;
double account_balance;
Here, in this example, age and account_balance are the identifiers. Also, one point to remember is that identifiers can’t be the same as the keywords you can’t declare int as the identifier.
Rules for naming identifiers
There are some rules for naming identifiers in C, and one should follow that. Let’s see:
- The first letter of an identifier should be either a letter either uppercase or lowercase or an underscore.
- The rest of the identifier names apart from the first letters can be letters, underscores, or digits.
- These are case-sensitive, as uppercase and lowercase letters have different meanings in C. For example, myname and myName are not the same in C, these will be considered as two different identifiers.
- You cannot use keywords like int, float, while, etc as identifiers.
- Some of the valid identifiers are num, age, num_23, and abc_23.
- Some of the invalid identifiers are 21abc, my-num, and this is my name.
I hope you all got a deep knowledge of the keywords in C Programming and must be excited to go into more depth about this particular series. Stay connected for the upcoming modules.
Until then, keep learning, Happy Coding!