Discussion: A Fraction of an Int
Execute the code to understand the output and gain insights into number division in C.
We'll cover the following...
Run the code
Now, it's time to execute the code and observe the output.
Press + to interact
#include <stdio.h>int main(){int a, b;a = 5; b = 4;printf("%d/%d = %f\n", a, b, a/b);return(0);}
Understanding the output
The compiler throws a warning because the %f
placeholder expects a float value, but the integer result of the division is interpreted incorrectly. The actual division, 5/4, yields 1. However, when printed with the %f
format specifier, it reads the memory ...