Global variables are created and defined outside any function, including the main() function. - C Function

C examples for Function:Global Variable

Description

Global variables are created and defined outside any function, including the main() function.

Demo Code

#include <stdio.h> 

void printLuckyNumber();  //function prototype 
int iLuckyNumber;   //global variable 

int main(){ /*from   w  ww . j a  v a 2  s .c  o m*/
   printf("\nEnter your lucky number: "); 
   scanf("%d", &iLuckyNumber); 
   printLuckyNumber(); 
} 

void printLuckyNumber() { 
   printf("\nYour lucky number is: %d\n", iLuckyNumber);  
}

Related Tutorials