fork download
  1. #include <stdio.h>
  2. int main (void)
  3. {
  4. printf ("1) Start of main declarations");
  5.  
  6. int myVal = 5; /* belongs to the main function */
  7.  
  8. printf ("\n\n=>Address of myVal in main: %lx\n\n", &myVal);
  9.  
  10. printf ("2) Let's enter the if statement:\n\n");
  11.  
  12. if (1 == 1) /* will always be true */
  13. {
  14. int myVal = 10; /* not the same as the first declared myVal */
  15.  
  16. printf ("=>myVal in the if statement is %i\n", myVal);
  17. printf ("=>Address of myVal in the if statement: %lx \n", &myVal);
  18.  
  19. } /* end if */
  20.  
  21. printf ("\n3) After the if statement:\n");
  22.  
  23. /* This is one declared before the if else condition */
  24. printf ("\n=> myVal after the if statement is %i\n", myVal);
  25. printf ("=>Address of myVal after the if statement: %lx \n", &myVal);
  26.  
  27. return (0);
  28.  
  29. } /* end main */
  30.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
1) Start of main declarations

=>Address of myVal in main: 7ffe77ddcf10

2) Let's enter the if statement:

=>myVal in the if statement is 10
=>Address of myVal in the if statement: 7ffe77ddcf14 

3) After the if statement:

=> myVal after the if statement is 5
=>Address of myVal after the if statement: 7ffe77ddcf10