So a friend of mine showed me a weird thing with printf()
in C.
#include <stdio.h>
#include <string.h>
int *init()
{
int a =10;
int *p = &a;
return p;
}
int main()
{
int *a = init();
printf("FIRST printf and value of a: %u\n", *a);
printf("SECOND printf and value of a %u\n", *a);
return 0;
}
Now I expected to get the same result at both printf()
calls but that's not the case as seen in this snip:
Of course, you can try it on your own system to convince yourselves.
I think it has something to do with the
printf()
function frame but I don't understand fully enough what is happening. Can you explain it to me please?