fork download
  1. #include <stdio.h>
  2.  
  3. /* GLOBAL, AUTO, and STATIC VARIABLE DECLARATION EXAMPLE */
  4.  
  5. int globalvar = 2; /* global variable is initialized only once */
  6. /* and its value is always held in memory */
  7.  
  8. void printit()
  9. {
  10. static int staticvar = 2; /* intialized only once, but since it is static */
  11. /* it value is always held in memory. */
  12.  
  13. int autovar = 2; /* local variable within printit */
  14.  
  15. globalvar++;
  16. staticvar++;
  17. autovar++;
  18.  
  19. /* Time line 2 */
  20.  
  21. printf("globalvar = %d \n", globalvar);
  22. printf("staticvar = %d \n", staticvar);
  23. printf("autovar = %d \n\n", autovar);
  24.  
  25. } /* printit */
  26.  
  27. int main()
  28. {
  29.  
  30. int x; /* local variable within main */
  31.  
  32. /* Time line 1 */
  33.  
  34. /* Call printit function three times */
  35. printit();
  36. printit();
  37. printit();
  38.  
  39. x = 5;
  40.  
  41. /* Time Line 3 */
  42. return(0);
  43.  
  44. } /* main */
Success #stdin #stdout 0s 5424KB
stdin
Standard input is empty
stdout
globalvar = 3 
staticvar = 3 
autovar   = 3 

globalvar = 4 
staticvar = 4 
autovar   = 3 

globalvar = 5 
staticvar = 5 
autovar   = 3