I'm trying to compile following simple program on a 64-bit machine:
#include <cstdio>
int main() {
float a,b,c;
a = 10.5;
b = 20.6;
c = a + b;
printf("%d \n", c);
return 0;
}
I compile it with following console command:
g++ -m32 file.cpp
When I execute the a.out file like this:
./a.out -m32
The result I get is this:
-1610612736
What is going on? What am I doing wrong? I get bogus result when compiling without the -m32 flag. Gcc acts the same way.
Your format specifier is wrong. It should be
printf("%f \n", c);