List of all Keywords in C

Short Recap - List of all Keywords in C Language with example 

1. auto: auto is a storage class specifier which is used to specify that a variable has a local storage. Example: auto int x = 10;

2. break: break is a keyword which is used to terminate a loop, switch statement or a labeled statement. Example: while(x < 10) {if(x == 5) break; x++; } 

3. case: case is a keyword which is used to mark the beginning of a statement for switch control. Example: switch(x) { case 1: printf("x is 1"); break; }

4. char: char is a keyword which is used to declare a character type variable. Example: char c = 'x'; 

5. const: const is a keyword which is used to declare a constant variable. Example: const int x = 10; 

6. continue: continue is a keyword which is used to skip the current iteration of a loop. Example: while(x < 10) {if(x == 5) continue; x++; } 

7. default: default is a keyword which is used to specify the default statement to be executed when a switch case statement is not matched. Example: switch(x) { case 1: printf("x is 1"); break; default: printf("x is not 1"); }

8. do: do is a keyword which is used to execute a statement or a block of statements in a loop. Example: do { x++; } while(x < 10);

9. double: double is a keyword which is used to declare a variable of type double. Example: double x = 3.14; 

10. else: else is a keyword which is used to execute a statement or a block of statements when an if statement is false. Example: if(x == 10) { printf("x is 10"); } else { printf("x is not 10"); }

11. enum: enum is a keyword which is used to declare a set of constants. Example: enum days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };

12. extern: extern is a storage class specifier which is used to declare a variable or a function which is visible outside a block. Example: extern int x; 

13. float: float is a keyword which is used to declare a variable of type float. Example: float x = 3.14; 

14. for: for is a keyword which is used to create a loop that consists of a set of three expressions and a statement or a block of statements. Example: for(int i=0; i<10; i++) { printf("%d", i); }

15. goto: goto is a keyword which is used to transfer the control from one part of the program to another. Example: goto label; ... ... label: printf("Hello World");

16. if: if is a keyword which is used to execute a statement or a block of statements if a condition is true. Example: if(x == 10) { printf("x is 10"); }

17. int: int is a keyword which is used to declare a variable of type int. Example: int x = 10; 

18. long: long is a keyword which is used to declare a variable of type long. Example: long x = 10; 

19. register: register is a storage class specifier which is used to declare a variable which should be stored in the CPU register. Example: register int x = 10;

20. return: return is a keyword which is used to return a value from a function. Example: int sum(int x, int y) { return x + y; }

21. short: short is a keyword which is used to declare a variable of type short. Example: short x = 10; 

22. signed: signed is a keyword which is used to declare a variable of type signed int. Example: signed int x = 10; 

23. sizeof: sizeof is a keyword which is used to calculate the size of a data type or a variable. Example: sizeof(int);

24. static: static is a storage class specifier which is used to declare a static variable. Example: static int x = 10;

25. struct: struct is a keyword which is used to declare a structure. Example: struct student { int id; char name[50]; };

26. switch: switch is a keyword which is used to execute a statement or a block of statements based on a condition. Example: switch(x) { case 1: printf("x is 1"); break; }

27. typedef: typedef is a keyword which is used to define a new name for an existing data type. Example: typedef int number;

28. union: union is a keyword which is used to declare a union. Example: union data { int x; char c; };

29. unsigned: unsigned is a keyword which is used to declare a variable of type unsigned int. Example: unsigned int x = 10; 

30. void: void is a keyword which is used to define a function that does not return a value. Example: void print() { printf("Hello World"); } 

31. volatile: volatile is a keyword which is used to declare a variable which may be changed by an external event. Example: volatile int x = 10;
Keywords in C Programming
autobreakcasechar
constcontinuedefaultdo
doubleelseenumextern
floatforgotoif
intlongregisterreturn
shortsignedsizeofstatic
structswitchtypedefunion
unsignedvoidvolatilewhile

Description of all Keywords in C


auto

The auto keyword declares automatic variables. For example:

auto int var1;

This statement suggests that var1 is a variable of storage class auto and type int.

Variables declared within function bodies are automatic by default. They are recreated each time a function is executed.

Since automatic variables are local to a function, they are also called local variables.


break and continue

The break statement terminates the innermost loop immediately when it’s encountered. It’s also used to terminate the switch statement.

The continue statement skips the statements after it inside the loop for the iteration.

for (i=1;i<=10;++i){
   if (i==3)
   continue;
   if (i==7)
   break;
   printf("%d ",i);
} 
 

Output

1 2 4 5 6

When i is equal to 3, the continue statement comes into effect and skips 3. When i is equal to 7, the break statement comes into effect and terminates the for loop.


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 1
    break;
    case '5':
    //some statements to execute when 5
    break;
    default:
    //some statements to execute when default;
}

char

The char keyword declares a character variable. For example:

char alphabet;

Here, alphabet is a character type variable.


const

An identifier can be declared constant by using the const keyword.

const int a = 5;

do…while

int i;
do 
{
   printf("%d ",i);
   i++;
}
while (i<10)

double and float

Keywords double and float are used for declaring floating type variables. For example:

float number;
double longNumber;

Here, number is a single-precision floating type variable whereas, longNumber is a double-precision floating type variable.


if and else

In C programming, if and else are used to make decisions.

if (i == 1)
   printf("i is 1.")
else
   printf("i is not 1.")

If the value of i is other than 1, the output will be :

i is not 1

enum

Enumeration types are declared in C programming using keyword enum. For example:

enum suit
{
    hearts;
    spades;
    clubs;
    diamonds;
};

Here, an enumerated variable suit is created having tags: heartsspadesclubs, and diamonds.


extern

The extern keyword declares that a variable or a function has external linkage outside of the file it is declared.


for

There are three types of loops in C programming. The for loop is written in C programming using the keyword for. For example:

for (i=0; i< 9;++i){
  printf("%d ",i);
}

Output

0 1 2 3 4 5 6 7 8

goto

The goto statement is used to transfer control of the program to the specified label. For example:

for(i=1; i<5; ++i)
{
    if (i==10)
    goto error;
}
printf("i is not 10");
error:
    printf("Error, count cannot be 10.");

Output

Error, count cannot be 10.

int

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

int count;

Here, count is an integer variable.


short, long, signed and unsigned

The short, long, signed and unsigned keywords are type modifiers that alter the meaning of a base data type to yield a new type.

short int smallInteger;
long int bigInteger;
signed int normalInteger;
unsigned int positiveInteger;
Range of int type data types
Data typesRange
short int-32768 to 32767
long int-2147483648 to 214743648
signed int-32768 to 32767
unsigned int0 to 65535

return

The return keyword terminates the function and returns the value.

int func() {
    int b = 5;
    return b;
}

sizeof

The sizeof keyword evaluates the size of data (a variable or a constant).

#include <stdio.h>
int main()
{
    printf("%u bytes.",sizeof(char));
}

Output

1 bytes.

register

The register keyword creates register variables which are much faster than normal variables.

register int var1;

static

The static keyword creates a static variable. The value of the static variables persists until the end of the program. For example:

static int var;

struct

The struct keyword is used for declaring a structure. A structure can hold variables of different types under a single name.

struct student{
    char name[80];
     float marks;
     int age;
}s1, s2;

typedef

The typedef keyword is used to explicitly associate a type with an identifier.

typedef float kg;
kg bear, tiger;

union

A union is used for grouping different types of variables under a single name.

union student {
    char name[80];
    float marks;
    int age;
}

void

The void keyword meaning nothing or no value.

void testFunction(int a) {
  .....
}

Here, the testFunction() function cannot return a value because its return type is void.


volatile

The volatile keyword is used for creating volatile objects. A volatile object can be modified in an unspecified way by the hardware.

const volatile number

Here, number is a volatile object.

Sincenumber is a constant, the program cannot change it. However, hardware can change it since it is a volatile object.

Comment
Name
Email