Demonstrate global and internal variables in C


Levels of difficulty: / perform operation:

C Program to Demonstrate global and internal variables. When variable declared outside the all the blocks, they are called global variables, and they are initialized by the system.

C Program

#include<stdio.h>
#include<conio.h>
int counter = 0;
int func(void);

main()
{
	counter++;
	clrscr();
	printf("counter is %2d before the call to func\n", counter);

	func();     /* call a function.  */

	printf("counter is %2d after the call to func\n", counter);
	getch();
}

int func(void)
{
	int counter = 10;   /* local.   */
	printf("counter is %2d within func\n", counter);
}


Output