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 can not be used as an identifier.
Let’s take an example:
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.
Keywords in C
There are a total of 32 keywords available in C. Let’s see them.
This is the total list of keywords available in the C library. Let’s see some of them in detail with their meanings.
auto keyword: 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: 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: It is a return type, which indicates that no value is to be returned i..e, null value.
goto: It is used as a jump statement as it takes you from one part of the program to another part.
enum: indicates the set of constants.
sizeof: tells the size of a particular variable.
for, while, do: These are the types of loops present in C Programming, used to perform different actions.
union: It represents the collection of the variables, which have the same memory storage and location.
if, else, switch, case, default: 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, like 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:
Here, in this example, age and account_balance are the identifiers. Also, one point is to remember is that identifiers can’t be the same as the keywords like 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, abc_23.
- Some of the invalid identifiers are 21abc, my-num, 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!