C Programming Tutorial

Keywords

• Keywords are some reserved/predefined words in the C programming language. They have special meanings to the compiler and can’t be changed.
• In C programming language we have 32 keywords.
• All the keywords must be written in lower case as C language is case-sensitive.

C Keywords


auto double struct int
break else switch long
case enum typedef register
char extern union return
const float unsigned short
continue for void signed
default goto volatile sizeof
do if while static

How do I use keywords in C

• Keywords can’t be used as identifiers as well as variables.
• When we write a program, we write some sequence of instructions. So to form those instructions we use keywords. In layman language, we can say that keywords are the basic building blocks for writing instructions in a C program.
For example, int, float, break, goto, if, etc.

An example of where and how keywords are used in a C program.

				
					#include<stdio.h>
int main()
{
    int a, b;
    printf("Showing how keywords are used.");
    return 0;
}
				
			
In the above-written program, int and return are keywords. The int is used to declare variables, and the return is used to return an integer type value in this program.

Why are keywords important in C ?

• Presently, for what reason do we use keywords, on the off chance that you know about programming in C, you should be knowing the significance of characterizing the data type of a variable, return type of a function, and other stuff?
• Each programming language has some reserved/predefined keywords. We need keywords to foster logic in the program.
• Keywords assume an exceptionally crucial part in making your program work in the right way.
• Like where and for what reason to utilize static int, const int, unsigned int, long int, register int, short int. You can see there is a lot of utilization of keywords to satisfy our prerequisites.

Examples of using keywords in C code

We are going to describe all the keywords with examples –

1) auto

The auto keyword declares automatic variables. For example:
				
					auto int abc;
				
			
This assertion recommends that abc is a variable of storage class auto and type int.

2) const

The const keyword is used to declare a constant data-type variable. For example,
				
					const float a=5.0;
				
			

3) switch, case, and default

The switch and case statement is used when a block of statements has to be executed among many blocks. For example:
				
					switch(expression)
{
     case '1': //some statements to execute when the case is 1
     break;
     case '5': //some statements to execute whenwhen the case is 5
     break;
     default: //some statements to execute when default;
}
				
			

4) if and else

In the C programming language, if and else statements are used in the decision-making. For example,
				
					if (a == 5)
{
    printf("a is 5.");
}
else
{
    printf("a is not 5.");
}
				
			

5) for

There are three types of loops in the C programming language. The for loop is from one of them and written in C programming using the keyword for. For example:
				
					for (i=0; i< 10;++i)
{
    printf("%d ",i);
}
				
			

6) int

The int keyword is used to declare integer type variables. For example:
				
					int star;
				
			

7) return

The return keyword terminates the function and returns the value given inside the program.
				
					int func()
{
    int b = 5;
    return b;
}
				
			

8) break and continue

The break statement terminates the innermost loop immediately when it is encountered. The continue statement skips the statements after it is inside the loop for the iteration. For example,
				
					for (i=0;i<=5;++i)
{
    if (i==2)
    {
        continue;
    }
    if (i==3)
    {
        break;
    }
    printf("%d ",i);
}
				
			

9) double and float

Keywords double and float are used for declaring floating data-type variables. For example,
				
					float num;
double longNum;
				
			

10) short, long, signed, and unsigned

The short, long, signed, and unsigned keywords are type modifiers in C programming language that alter the meaning of a base data type to produce a new type. For example,
				
					short int smallint;
long int bigint;
signed int normalint;
unsigned int positiveint;
				
			

11) void

The void indicates that the function takes no parameters. For example,
				
					void functionforexample(int a)
{
    .....
}
				
			

12) do…while

Utilizing the do-while loop, we can repeat the execution of a few pieces of the statements. For example,
				
					int i;
do
{
    printf("%d ",i);
    i++;
}
while (i<10);
				
			

13) char

The char keyword declares a character data-type variable. For example,
				
					char anyalphabet;