Your teacher is mistaken, but not completely.
Variables declared in a function are auto by default, not static .
int foo(void) { static int x; int y; auto int z; }
This means that in the function above, y is auto, just like z, even if the auto keyword is not used in its declaration. By the way, the auto keyword is almost never used. Many C (and C) programmers do not even know that auto is a keyword because it is used so rarely.
Being an auto variable usually means that the variable is stored on the software system stack or in registers or some combination thereof. It can be in different places at different times during the execution of a function, and local variables that are in the register are often pushed onto the stack when another function is called. Some local variables can even be optimized, which means that at some point the compiler was able to determine that the specific value of the future variable is no longer required to satisfy the input needs of the future code (or the variable does not change and its value is simply encoded in the instructions). This complicates the use of debuggers on optimized code.
When you take the address of a local variable, the compiler then tries to lock it to a specific address (possibly by storing it on the stack).
When most compilers look at your code, they will see that the names of these local variables are not used after they are declared and may decide that they simply do not store their values anywhere. Even if it stores these values on the stack, it can also push other values on the stack before setting up the printf call. Just as the compiler should not contain the variables you named, it can also create its own temporary variables.
source share