C Keywords


Keywords are the reserved words used in programming. Each keywords has fixed meaning and that cannot be changed by user.

int fee;

Here, int is a keyword that indicates, 'fee' is of type integer.


auto Keyword

auto is used to define a variable of storage class automatic. For example:

Example

auto int var1;

This statement suggests that var1 is a variable of storage class auto and data 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, automatic variables are also called local variables.


break and continue Keyword

The break statement is used to jump out of the innermost enclosing loop (while, do, for or switch statements) explicitly and pass control to next statement immediately following the loop. In other hand, continue statement is used to skip certain statements inside the loop.

Example

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

It is because, when i=3, continue statement comes to effect and skips 3 and when i=7, break statements come to effect and terminates the loop.


switch, case and default Keyword

The switch statement tests the value of a expression and test with the different "case" values. We can use "default" value, if it doesn't matches any of "case" values.

Example

switch(option){
    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 is used for indicating the variable is of the type character.

Example

char variable0;

Here, variable0 is a variable of type character.


const Keyword

const makes the value of a pointer or a variable unmodifiable.

Example

const int a = 5;

In this example, a is the constant and its value is 5. This value cannot be changed in program.


do and while Keyword

while and do are used for looping in C.

Example

i = 2;
while (i<10) {
    print("%d ",i)
    i++;
}
Output
2 3 4 5 6 7 8 9.

If programmer finds easy to write statements to be executed before writing test condition, do...while loop is used.

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

double and float Keyword

double and float are used for indicating floating type variables. Keywords float and double represents single precision and double precision floating point data respectively.

Example

float variable1;
double variable2;

if and else Keyword

if and else are used in decision making in C.

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

extern Keyword

Keyword extern is used for indicating the variable is external and is declared outside every function and can be accessed by any function.

Example

#include <stdio.h>
extern i=5;
void print1(){
    printf ("%d ",i);
}
int main() {
    printf("%d ",i);
}
return 0;
}
Output
5 5

for Keyword

Keyword for is used for looping in C.

Example

for (i=0;i<9;++i){
     printf("%d ",i);
}
Output
0 1 2 3 4 5 6 7 8

goto Keyword

Keyword goto is used for unconditional jump to a labeled statement inside that function.

Example


int Keyword

int is used for indicating the variable is of type integer.

Example

int var0;

short, long, signed and unsigned Keyword

short, long, signed and unsigned are type modifiers that alters the meaning of base data type to yield new type.

Example

short int var1;
long int var2;
signed int var3;
unsigned int var4;

Range of int type data types
DatatypesRange
short int-32768 to 32767
long int-2147483648 to 214743648
signed int-32768 to 32767
unsigned int0 to 65535

return

Keyword return terminates the execution of current function and returns the value to the calling function.

Example

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

This function func() returns 5 to to the calling function.


sizeof Keyword

sizeof is used to find the number of bytes of an object.

Example

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

register Keyword

Variable of storage class register are much faster than normal variables.

Example

register int var1;

static Keyword

static is used for indicating the variable is of storage class static. The value of the static variables persists until the end of the program.

Example

static int var;

Here, var is a variable of storage class static.


struct Keyword

struct is used in creating a structure which provide means to group different types of variable under one name for easier handling.

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

typedef Keyword

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

typedef int part;
part acer,hp;

Here, the use of typedef is to create a type part and this part type is used in declaring variables acer and hp.


union Keyword

Union is used in creating a union which provide means to group different types of variable under one name for easier handling.

Example

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

void Keyword

void is used to indicate that a function takes no arguments or returns no value.

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

Here, function no_return( ) can take value but, can't return value because, the return type is void.


Share this article on