keywords in C | Readstall

keywords in C

06-02-19 Bhaskar Sampala 0 comment

Keywords:
Keywords are those words which meaning is already definedby compiler.
There are 32 keywords in C.
These words cannot be used as variable name.
C keywords are also called as reserved words.
Keywords in programming

Auto          Break           Case          Char

Const        Continue     Default      Do

Double     Else              Enum        Extern

Float         For               Goto           If

Int             Long            Register     Return

Short        Signed         Size of        static

Struct        Switch        Typedef    union

Unsigned   Void           Volatile      While

Description of all Keywords in c
auto:

The auto keyword declares automatic variables. For example:
auto int a;
This statement suggests that a 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 makes program jump out of the innermost enclosing loop (while, do, for or switch statements) explicitly.
The continue statement skips the 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 3 4 5 6
When i is equal to 3, continue statement comes into effect and skips 3. When i is equal to 7, 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(ch)
{
case 1: printf(“1”);
break;
case 2: printf(“2”);
break;
default: printf(“invald”);


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 const keyword.
constint a=6;

do…while
int i;
do
{
Print(“%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 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
prinf(“i is not 1.”)
If value of i is other than 1, 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;
};
Here, a enumerated variable suit is created having tags: hearts, spades, clubs 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 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 keyword is used for unconditional jump to a labeled statement inside a function. 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 declares integer type variable. For example:
int count;
Here, count is a integer variable.


short, long, signed and unsigned:
The short, long, signed and unsigned keywodrs are type modifiers that alters the meaning of a base data type to yield a new type.
intsmallInteger;
long intbigInteger;
signed intnormalInteger;
unsigned intpositiveInteger;
Range of int type data types

Data types       Range

short int          -32768 to 32767

long int           -2147483648 to 214743648

signed int       -32768 to 32767

unsigned int   0 to 65535


return:
The return keyword terminates the function and returns the value.
int fab
{
int b = 5;
return b;
}
This function fab() returns 5 to the calling function.


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.
int var1;


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


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.
float kg;
kg bear, tiger;


union:
A Union is used for grouping different types of variable under a single name.
union student
{
char name[80];
float marks;
int age;
}


void:
The void keyword indicates that a function doesn’t return any value.
void test(int a)
{
…..
}
Here, function  test()cannot return a value because the 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.
Since, number is a constant variable, the program cannot change it. However, hardware change it since it is a volatile object.



Leave a reply