J
john
The code:
#include <cstdio>
int main()
{
using namespace std;
int i;
printf("%ld\n%n", 1, &i);
printf("==>%d\n", i);
printf("%ld\n%n", 123456, &i);
printf("==>%d\n", i);
}
in my system produces:
[john@localhost src]$ ./foobar-cpp
1
==>2
123456
==>7
[john@localhost src]$
I expected:
"[john@localhost src]$ ./foobar-cpp
1
==>1
123456
==>6
[john@localhost src]$ "
It looks like it increments the value written to i with 1 more, than it
should. Is this a bug of my compiler, or am I wrong?
#include <cstdio>
int main()
{
using namespace std;
int i;
printf("%ld\n%n", 1, &i);
printf("==>%d\n", i);
printf("%ld\n%n", 123456, &i);
printf("==>%d\n", i);
}
in my system produces:
[john@localhost src]$ ./foobar-cpp
1
==>2
123456
==>7
[john@localhost src]$
I expected:
"[john@localhost src]$ ./foobar-cpp
1
==>1
123456
==>6
[john@localhost src]$ "
It looks like it increments the value written to i with 1 more, than it
should. Is this a bug of my compiler, or am I wrong?