Tuesday 1 October 2013

Keywords in C

Constant                                                                                                                Data Type



There are 32 keywords in C.
Keyword means the reserved words whose meaning is already known by the compiler.
The meaning of keywords cannot be redefined by the user.

List of Keywords:-


auto:-define variable of storage class automatic.
We can also say that automatic variables are local variables because each time they recreate when function executed and local to that functions.

Ex:-auto int i;

Break:-by using this we can come out from the loop or body in which we write break.

Ex:-

                     while(i<10)
                        {
                            if(i==5)
                            break;
                            i++;
                        }

when the value of i becomes 5 it come out from the while loop.


case:-we use case keyword to provide different condition to switch loop.it matches with different cases and executes those cases which matches with the condition..

Ex:-
int i=5;
switch(i)
{
case '4':
printf(" case 1");
break;
case '5':
printf("case 5");
break;
}
so it prints case 5.

char:-to declare the variable as character type.
Ex:- char a;

a takes the only one character at a time.

const:-if we declare any variable with a const keyword then we cannot modify the value of that variable.

Ex:-  const int i=10;

so we cannot modify the value of i throughout the program.


continue:-it is used when you want to skip some statement.

Ex:-   while(i<5)
          {
if(i==3)
continue;
printf("%d",i);
}

output:-1 2 4 5

default:-we can also say that it is opposite of case when in switch no case matches then it executes the default.

Ex-
int i=6;
switch(i)
{
case '4':
printf(" case 1");
break;
case '5':
printf("case 5");
break;
default:
printf("no case matches");
break;
}

output: no case matches

do:-it is used for looping.

Ex:-
           int j=0;
           do
             {
             printf("%d",j);
              j++;
              }while(j<10);

double:-it is used for declaring variables of floating type or decimal type.it is declared double precision type floating variables.

Ex:-double i;

if and else:-
both keyword are using for providing conditions.condition true executes if block , condition false executes else block.

EX:-  if(i==5)
         {
            printf("if executed");
         }
      else
        {
            printf("else executed");
        }

if block only executed when the value of i is 5 and the  value of i other than 5 then else block executed.

enum:-it is used to from a group of constants of integer data type. mainly termed as enumerated data type.

enum a={variable 1 ,variable 2 , variable 3};

extern:-it is used to define the variable as external in which we define the variable at top and used everywhere in the program and we can also say that as a global variable.

EX:-
              extern int i=1;
               main()
                   {
printf("%d",i);
}
method()
{
printf("%d",i);
}

both prints i =1.

float :- it is also the keyword same as double used for declaring the variable of decimal type.

Ex:- float a;

for:-used for looping.it contains 3 arguments
initialization
condition
increment\decrement

for(int i=0,i<10;i++)
printf("%d",i);

output:0 1 2 3 4 5 6 7 8 9

goto:-used for jumping. for this first we set the label and if you want to execute some statement on particular condition.

Ex;-
while(i<3)
{
printf("%d",i);
if(i==2)
goto label;
}
label:
printf("value of i =2");

when value of i become 2 it excutes the label.

int:-used for declaring variable integer type.
Ex;- int a;
a only takes the integer value.

long;-it modified the value of int type it increases the range of int data type.
 range of long  -2147483648 to 214743648

Ex:- long int a;

register :-accessing of register type variables are much faster then normal variables.
Ex;-register int a;

return:- it is used for terminating the function and return some value to the calling function.

Ex:-int sum()
{
int z=a+b;
return z;
}
it returns the value of z.

short:-it modified the range of int type.
short int -32768 to 32767

Ex:- short int a;

signed:-it modified the range of int type.
range   -32768 to 32767

EX:-signed int a;

sizeof:-find number of bytes of an object.

Ex:-
main()
{
printf("%u",sizeof(char));
}

static:-the value of static variable lives throughout the execution of the program.

Ex;static int a;

struct:-it is used for making structure.in which we can insert values of different datatypes.

Ex:-  struct emp
{
char name[20];
int age;
float weight;
}e;

switch:-it is used for providing multiple conditions .in "if " we can provide only one conditon at a time.
this is advanced of if

Ex:-
int i=6;
switch(i)
{
case '4':
printf(" case 1");
break;
case '5':
printf("case 5");
break;
default:
printf("no case matches");
break;
}


typedef;-to provide a data type explicitly to an identifier.

Ex;-
typedef int a;
a,i,j;

union:-

unsigned:-it modifies the range of int.
 range:-0 to 65535

Ex;- unsigned int a;

void:-means no return type and no parameter or arguments.

volatile;-used to create volatile object.it can be  modified by the hardware.

Ex; const volatile  a;

we cannot change the value of a through the program but hardware can change the value of a because we declared the "a" as a volatile.

while:- it is used for looping

Ex;- 
int i=1;
while(i<10)
{
printf("%d",i);
i++
}

output: 1 2 3 4 5 6 7 8 9


No comments :

Post a Comment