Can any one explain what is global variable in c with example.
Tags: asked May 9, 2012Variables that are known throughout the program and may be used by any piece of code is called a global variable. Also, they will hold their value throughout the program’s execution. Global variables can be created by declaring them outside of any function. Global variables are helpful when many functions in the program use the same data. Storage for global variables is in a fixed region of memory set aside for this purpose by the compiler. In the following program, the variable count has been declared outside of all functions.
Example:
#include "stdio.h"
int count; /* count is global */
void func1(void);
int main(void)
{
count = 100;
func1();
return 0;
}
void func1(void)
{
printf("count is %d", count); /* will print 100 */
}
Please login to post questions.
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com