Possible Duplicate:
Why does printf print wrong values?
#include<stdio.h>
int main(int argc, const char *argv[]){
float f1 = 125.2f;
printf("\n [%f] [%d] [%g]",f1,f1,f1);
printf("\n [%f] [%g] [%d]",f1,f1,f1);
printf("\n [%g] [%f] [%d]",f1,f1,f1);
printf("\n [%g] [%d] [%f]",f1,f1,f1);
printf("\n [%d] [%g] [%f]",f1,f1,f1);
printf("\n [%d] [%f] [%g]",f1,f1,f1);
getchar();
}
I can see different output from each printf, though printing the same variable with same format identifier.
printfis not type safe so using a incorrect format descriptor results in Undefined Behavior.An Undefined Behavior means that any observable behavior is possible because the code is not abiding the rules laid out by the standard.