I was reading about %n
format specifier in C at this question. But when I tried the following program on different C++ compilers, it gave me different outputs.
Why? What is the reason? Is there undefined or implementation defined behavior occurring?
#include<stdio.h>
int main()
{
int c = -1;
printf("geeks for %ngeeks ", &c);
printf("%d", c);
getchar();
return 0;
}
Output:
Code blocks 13.12: (correct output)
geeks for geeks 10
Borland/CodeGear/Embarcadero C++: (correct output)
geeks for geeks 10
Orwell Dev C++:
geeks -1
Microsoft Visual Studio 2010:
Debug assertion failed ("'n' format specifier disabled",0)
Aucun commentaire:
Enregistrer un commentaire