Hello, I am new to c++ programming. This is just a simple test program and I was curiously messing with outputting some numbers when I observed this peculiar behavior.
int main() {
int quotient = 25 / 7;
std::cout << quotient << std::endl;
printf("%e\n", quotient);
printf("%f\n",quotient);
printf("%g\n", quotient);
std::cout << 25.0 / 7.0 << std::endl;
printf("%g\n", (25.0 / 7.0));
}
Output:
3
1.482197e-323
0.000000
1.4822e-323
3.57143
3.57143
I am expecting the integer variable outputs to always be 3 but in reality, see that only the std::cout prints 3 while the 3 printf calls with specifiers print essentially 0. I have tried to do individual research and think I have a decent grasp on what the %g specifier is trying to do but cannot find evidence of why I am seeing these results.
Thanks!