#include
//Compiler version gcc 6.3.0
int main(void)
{
float a=10;
printf(\"%f\"+1,a);
return 0;
}
Output -- d
The output is different every time because it is undefined to read from an unknown address.
Compare with this code:
#include
int main(){
printf("Hello,World\n"+1);
}
It looks like the famous Hello,World but in fact it is the less known version ello,World. The argument to printf
is string or more precisely a pointer to a null terminated sequence of chars in memory, when "Hello"+1
is evaluated, the pointer is incremented by one and points to "ello,World"
.
Your program will first print the the string "f" and in the second case is a memory overrun error, it will print whatever is found in the memory location 36 bytes away from the string. This random memory location is likely to have a different contents every time.