II-246 Programming Concepts
2.
#include <stdio.h>
#include <conio.h>
void main()
{
int x=11;
clrscr();
printf(" x=%d",x);
{
float x=2.5;
printf("x=%g",x);
}
{
char *x="Auto Storage Class";
printf("x=%s",x);
}
}
OUTPUT:
x = 11 x = 2.5 x = Auto Storage Class
3.
#include <stdio.h>
#include <conio.h>
int v=10;
void main()
{
clrscr();
call1();
call2();
printf("In main()");
}
call1() { printf(" In call1()"); }
call2() { printf(" In call2()"); }
OUTPUT:
In call1() In call2() In main()
M11_ITL-ESL4791_02_SE_C11.indd 246 12/22/2012 5:05:16 PM
Storage Class II-247
4.
#include <stdio.h>
#include <conio.h>
int v=10;
void main()
{
clrscr();
call1();
call2();
printf(" In main()");
}
call1() { printf("In call1() v=%d",v); }
call2() { printf("In call2() v=%d",v); }
OUTPUT:
In call1() v = 10 In call2() v = 10 In main()
5.
#include <stdio.h>
#include <conio.h>
int v=10;
void main()
{
clrscr();
for(;;)
print();
}
print()
{
int static m;
m++;
printf(" %d",m);
if(m==3) exit(0);
}
OUTPUT:
1 2 3
M11_ITL-ESL4791_02_SE_C11.indd 247 12/22/2012 5:05:16 PM
II-248 Programming Concepts
6.
#include <stdio.h>
#include <stdio.h>
#include <conio.h>
void main()
{
auto int j=1;
clrscr();
{
{
{ printf("%d",j);
}
printf("%d",j);
}
printf("%d",j);
}
}
OUTPUT:
1 1 1
7.
#include <stdio.h>
#include <stdio.h>
#include <conio.h>
void main()
{
auto int j=1;
clrscr();
{
auto int j=2;
{
auto int j=3;
printf("%d",j);
}
printf("%d",j);
}
printf("%d",j);
}
OUTPUT:
321
M11_ITL-ESL4791_02_SE_C11.indd 248 12/22/2012 5:05:16 PM
Storage Class II-249
8.
#include <stdio.h>
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
increment();
increment();
increment();
}
increment()
{
static int j=1;
printf(" %d",j);
j++;
}
OUTPUT:
1 2 3
Find the bug/s in the following programs.
1.
auto int x=20;
#include <stdio.h>
void main()
{
auto int x=10;
clrscr();
printf(" x=%d",x);
}
Bug: Automatic variables cannot be deļ¬ned outside functions
2.
#include <stdio.h>
void main()
{
register x=10;
printf(" x=%d",x);
}
Bug: No bug
M11_ITL-ESL4791_02_SE_C11.indd 249 12/22/2012 5:05:16 PM
II-250 Programming Concepts
3.
#include <stdio.h>
void main()
{
clrscr();
value();}
static value()
{
printf("Hi");
}
Bug: No Bug
4.
#include <stdio.h>
void main()
{
int x=25;
clrscr();
printf("%d ",x);
show();
}
show() { printf("%d",x); }
Bug: Compiler error
5.
#include <stdio.h>
void main()
{
int count =5;
printf(" %d",count--);
if(count!=0)
main();
}
Bug: No bug. But, the count should be static
M11_ITL-ESL4791_02_SE_C11.indd 250 12/22/2012 5:05:16 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset