Global variables in C

A global variable is used throughout the program. It can be used by different code blocks. It is always declared outside the function. It is generally used when many functions have to use the same variables. For Example:

#include <stdio.h>

int count;

void function1(void);

void function2(void);

int main(void)


count = 25;


return 0;


void function1(void)


int temp;

temp = count;


printf(“count is %d”, count); }

void function2(void)


int count;

for(count=1; count<10; count++)



Here count is the global variable which has been used throughout the program.

Leave a Reply