fork(10) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #pragma GCC optimize ("O0")
  4.  
  5. // uninitialized variable
  6. int g1;
  7. int g2;
  8.  
  9. //iniatialized variable
  10. int g3=5;
  11. int g4=7;
  12.  
  13. // function to test stack
  14. void func2() {
  15. int var1;
  16. int var2;
  17. printf("On Stack through func2:\t\t %u %u\n",&var1,&var2);
  18. }
  19.  
  20. void func() {
  21. int var1;
  22. int var2;
  23. printf("On Stack through func:\t\t %u %u\n",&var1,&var2);
  24. func2();
  25. }
  26.  
  27. int main(int argc, char* argv[], char* evnp[]) {
  28.  
  29. // Command line arguments
  30. printf("Cmd Line and Env Var:\t\t %u %u %u\n",&argc,argv,evnp);
  31.  
  32. // Local variable will go to stack and stack should grow downward
  33. int var1;
  34. int var2;
  35. printf("On Stack through main:\t\t %u %u\n",&var1,&var2);
  36. func();
  37.  
  38. // Dynamic Memory should go to heap and should be increasing
  39. void *arr1 = malloc(5);
  40. void *arr2 = malloc(5);
  41. printf("Heap Data:\t\t\t\t\t %u\n",arr2);
  42. printf("Heap Data:\t\t\t\t\t %u\n",arr1);
  43. free(arr1);
  44. free(arr2);
  45.  
  46. // Uninitialized and iniatialized Global Variable
  47. printf("Global Uniniatialized:\t\t %u %u\n",&g1,&g2);
  48. printf("Global iniatialized:\t\t %u %u\n",&g3,&g4);
  49.  
  50. //Static Code must go to Text section
  51. printf("Text Data:\t\t\t\t\t %u %u",main,func);
  52. return 0;
  53. }
Success #stdin #stdout 0s 2424KB
stdin
Standard input is empty
stdout
Cmd Line and Env Var:		 3216684080 3216684228 3216684236
On Stack through main:		 3216684052 3216684048
On Stack through func:		 3216684012 3216684008
On Stack through func2:		 3216683964 3216683960
Heap Data:					 144969752
Heap Data:					 144969736
Global Uniniatialized:		 134519328 134519332
Global iniatialized:		 134519320 134519316
Text Data:					 134513984 134513936