#include"stdio. h"
#include"conio. h"
#include"cubesu bpr.c"
void show();
void main()
{
clrscr();
printf("\nnumbe r square cubes");
printf("\n---- ----- -----");
for(a=1;a<=10;a ++)
{
b=a*a;
c=a*a*a;
printf(" \n %d \t%d \t%d ",a ,b,c);
}
printf("\n---------------\n");
printf("\n press any key\n");
getch();
show();
printf("\npress any key");
getch();
display();
printf("\npress any key");
getch();
getch();
}
void show()
{
printf("\n Last value of a-->%d",a);
printf("\n last value of b-->%d",b);
printf("\n last value of c-->%d",c);
}/*completd*/
*************** *********
*************** ********
CUBESUBPR.c
*************** ************
static int a,b,c;
void display()
{
printf("\n last value of a-->%d",a);
printf("\n Last value of b-->%d",b);
printf("\n last value of c-->%d",c);
}/*completed*/
*************** *************** *************** *
OUTPUT
*************** *************** ***************
number square cubes
---- ----- -----
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
------ ----- -------
press any key
Last value of a-->11
last value of b-->100
last value of c-->1000
press any key
last value of a-->11
Last value of b-->100
last value of c-->1000
*************** *************** ***********
my questions
*************** *************** ***********
in this program we are using static in tat second program.....
1)i had read tat in one book the author said ,"where the static is used that type of variable can't be used in another program........ ............... ..............
we are using static in tat second program . But if i execute first program, tat program executes without any error..if i change the static from this program to tat program at that time also it executes without any error...so what is the use of static in c.....this static variable can be shared in both program ..if anybody knows pls tell....
#include"conio. h"
#include"cubesu bpr.c"
void show();
void main()
{
clrscr();
printf("\nnumbe r square cubes");
printf("\n---- ----- -----");
for(a=1;a<=10;a ++)
{
b=a*a;
c=a*a*a;
printf(" \n %d \t%d \t%d ",a ,b,c);
}
printf("\n---------------\n");
printf("\n press any key\n");
getch();
show();
printf("\npress any key");
getch();
display();
printf("\npress any key");
getch();
getch();
}
void show()
{
printf("\n Last value of a-->%d",a);
printf("\n last value of b-->%d",b);
printf("\n last value of c-->%d",c);
}/*completd*/
*************** *********
*************** ********
CUBESUBPR.c
*************** ************
static int a,b,c;
void display()
{
printf("\n last value of a-->%d",a);
printf("\n Last value of b-->%d",b);
printf("\n last value of c-->%d",c);
}/*completed*/
*************** *************** *************** *
OUTPUT
*************** *************** ***************
number square cubes
---- ----- -----
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
------ ----- -------
press any key
Last value of a-->11
last value of b-->100
last value of c-->1000
press any key
last value of a-->11
Last value of b-->100
last value of c-->1000
*************** *************** ***********
my questions
*************** *************** ***********
in this program we are using static in tat second program.....
1)i had read tat in one book the author said ,"where the static is used that type of variable can't be used in another program........ ............... ..............
we are using static in tat second program . But if i execute first program, tat program executes without any error..if i change the static from this program to tat program at that time also it executes without any error...so what is the use of static in c.....this static variable can be shared in both program ..if anybody knows pls tell....
Comment