in turboc++
-------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
printf("value of a and b from main function are=%d and %f\n",a,b);
function();//function calling
return 0;
}
void function()//function body line
{
printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}
---------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
printf("value of a and b from main function are=%d and %f\n",a,b);
function();//function calling
getch();
return 0;
}
void function()//function body line
{
printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}
-------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
printf("value of a and b from main function are=%d and %f\n",a,b);
function();//function calling
return 0;
}
void function()//function body line
{
printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}
---------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
printf("value of a and b from main function are=%d and %f\n",a,b);
function();//function calling
getch();
return 0;
}
void function()//function body line
{
printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}
No comments:
Post a Comment