Reserved Keywords


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

Data Types
int : Integer type के variable को declare करने के लिए 'int' data type का इस्तेमाल किया जाता है | for e.g. int a=0; 'a' is integer variable.

char : Character type
के variable को declare करने के लिए 'char' data type का इस्तेमाल किया जाता है | for e.g. char ch='Hello'; 'ch' is character variable.

double : Double type
के variable को declare करने के लिए 'double' data type का इस्तेमाल किया जाता है | इसका उपयोग ज्यादातर नहीं होता , इसके बदले में float data type का इस्तेमाल होता है | for e.g. double num=3.5; 'num' is double variable.

float : Floating type
के variable को declare करने के लिए 'float' data type का इस्तेमाल किया जाता है | for e.g. float var=1.20; 'var' is floating variable.


Loops
Example
Output
Do...While Loop
void main(){
int i=0;
do{
printf("%d\n",i);
i++;
}
while(i<5);
}
0
1
2
3
4
For Loop
void main(){
int i;
for(i=0; i<5; i++){
printf("%d\n",i);
}
}
0
1
2
3
4

Decision Control/Statements
Example
Output
if...else Loop
void main(){
int i=10;
if(i==10){
printf("i is equal to 10");
}
else{
printf("i is not equal to 10");
}
}
i is equal to 10
switch..case..default
void main(){

switch(2){

case 1:
printf("expression is 1");
break;
case 2:
printf("expression is 2");
break;
default:
printf("unknown expression");
}
expression is 2

Storage Classes
Example
Output
auto
void main()
{
auto int num = 10 ;
{
auto int num = 5 ;
printf("num : %d\n",num);
}
printf("num : %d",num);
}
num : 5
num : 10
extern
extern int num;
void main()
{
printf("num value comes from General File is %d", num);
}
num value comes from General File is 10
register
void main()
{
register int num=1;
printf("These Number is stored in CPU's register\n");
printf("%d ",num);
}
These Number is stored in CPU's register
1
static
function(){
static int num = 1;
printf("%d",num);
num++;
}
void main()
{
int i;
for(i=0; i<10; i++){
printf("\n");
function();
}
}
1
2
3
4
5
6
7
8
9
10

Jumping Statements
Example
Output
goto
void main(){
int num1, num2, num3;
char ch;
yes : printf("Enter two values\n");
scanf("%d%d",&num1, &num2);
num3 = num1 + num2 ;
printf("Addition of %d and %d is %d\n", num1, num2, num3);
printf("\nDo you want to continue y(yes) or n(No)");
scanf(" %c",&ch);
if(ch=='y'){
goto yes;
}
else if(ch=='n'){
goto no;
}
else{
printf("You entered other key");
}
no : printf("Do you want to exit ?, Press Enter");
}
Enter two values
5
6
Addition of 5 and 6 is 11

Do you want to continue y(yes) or n(No)n
Do you want to exit ?, Press Enter
continue
void main(){
int i=0;
while ( i < 20 ){
printf("value of i is %d\n", i);
i++;
if ( i == 10 )
printf("Continued Values\n");
continue;
}
}
value of i is 0
value of i is 1
value of i is 2
value of i is 3
value of i is 4
value of i is 5
value of i is 6
value of i is 7
value of i is 8
value of i is 9
Continued Values
value of i is 10
value of i is 11
value of i is 12
value of i is 13
value of i is 14
value of i is 15
value of i is 16
value of i is 17
value of i is 18
value of i is 19

struct
struct Student {
char stud_name[30];
};
void main(){
struct Student info;
strcpy( info.stud_name, "Pradeep Rana");
printf( "Student name is %s ", info.stud_name);
}
Output :
Student name is Pradeep Rana

return
Number(){
int a=10, b=5, c;
c = a + b;
return c;
}
void main(){
printf("Addition of a and b is %d",Number());
}
Output :
Addition of a and b is 15

typedef
void main(){
typedef int num;
num num1;
printf("Enter value of num1 ");
scanf("%d", &num1);
printf("Value of num1 is %d", num1);
}
Output :
Enter value of num1 5
Value of num1 is 5

union
union Student {
char stud_name[30];
};
void main(){
union Student info;
strcpy( info.stud_name, "Pradeep Rana");
printf( "Student name is %s ", info.stud_name);
}
Output :
Student name is Pradeep Rana

const
void main(){
const int num=1;
printf("num = %d",num);
}
Output :
num = 1

enum
enum Days {Sun, Mon, Tue, Wed, Thu, Fri, Sat };
void main()
{
printf("%d, %d, %d, %d, %d, %d, %d",Sun, Mon, Tue, Wed, Thu, Fri, Sat);
}
Output :
0, 1, 2, 3, 4, 5, 6

sizeof
void main(){
printf("%d",sizeof(int));
}
Output :
4

Comments

Popular Posts