Nothing here "disappears", this happens because, the inner scope takes precedence over the outer scope for identifiers with overlapping scope.
Quoting C11, chapter §6.2.1 (emphasis mine)
[...] If an identifier designates two different entities in the same name
space, the scopes might overlap. If so, the scope of one entity (the inner scope) will end
strictly before the scope of the other entity (the outer scope). Within the inner scope, the
identifier designates the entity declared in the inner scope; the entity declared in the outer
scope is hidden (and not visible) within the inner scope.
So, in your case, (follow the comments)
#include <stdio.h>
int main (void) { //note the correct signature
int i = 3; //outer scope of i
printf("%d\n", i);
if (i == 3) {
i = i + 1; //this happens in "outer" scope, i value changed...
//---------------------> |-----inner scope starts, outer scope gets hidden
int i = 6; // |
printf("%d\n", i); // |
i = i + 1; // |
}//------------------------> |-----inner scope ends, outer scope resumes
if (i == 3) { // hey. look , other scope is back!!!
printf("%d\n", i);
}
return 0;
}
i = i + 1increments the outeri, so the secondifis never entered.printf("%d\n", i);after secondi = i + 1;?