fork download
  1. #include <stdio.h>
  2.  
  3. /* a global variable, does not belong to any function */
  4. /* It is initialized to zero automatically */
  5. /* It can be any valid C variable name. */
  6. int globalValue;
  7.  
  8. // ***************************************************
  9. // Function: somefunc
  10. //
  11. // Description: Updates a global variable
  12. //
  13. // Parameter: number - an integer number
  14. //
  15. // Returns: void (global variable is updated)
  16. // ***************************************************
  17.  
  18. void somefunc (int number)
  19. {
  20. int answer; /* squared value */
  21.  
  22. globalValue *= 10; /* update global var */
  23.  
  24. answer = globalValue * globalValue; /* use it */
  25.  
  26. }
  27.  
  28. int main ( )
  29. {
  30. int localValue; /* a local variable value */
  31.  
  32. globalValue += 10; /* add 10 to globalValue */
  33.  
  34. localValue = globalValue; /* set values to it */
  35.  
  36. somefunc (localValue);
  37.  
  38. printf("localValue = %i, globalValue = %i\n", localValue, globalValue);
  39.  
  40. return (0);
  41. }
  42.  
Success #stdin #stdout 0.01s 5224KB
stdin
Standard input is empty
stdout
localValue = 10, globalValue = 100