Computer Programming C Laboratory: Functions C Programs

C Program to demonstration of global variable

Programs Using Functions - C Programming

/* C Program to demonstration of global variable */

#include <stdio.h>

int a; /* global variable */

main()

{

a=39;

int f1();

int f2();

int f3();

printf("A..... %d\n", a);

printf("A..... %d\n", fl());

printf("A..... %d\n", f2());

printf("A..... %d\n",f3());

} /* main */

f1()

{

        a=a+10;

        return(a);

} /* fl */

f2()

{

        a=a+20;

        return(a);

} /* f2 */

f3()

{

        a=a+30;

        return(a);

} /* f3 */

OUTPUT

A.....39

A.....49

A.....69

A.....99

EXPLANATION: In the above program the variable a is declared as global declaration. This variable a is available any where in the program. The user‒defined functions f1(), f2(), and f(3) are accessed the a and executed the body of the statement then, it returns to the main program. Note that in all user‒defined functions the value of a does not change, hence it is global variable.

 

Computer Programming C Laboratory: Functions C Programs : Tag: C Programming : - C Program to demonstration of global variable


Computer Programming C Laboratory: Functions C Programs



Under Subject



Related Subjects