#define IVAR 100
double x, y;
int a, b, i;
a = 9;
b = 4;
y = 5.0;
x = b / a;
double x, y;
int a, b, i;
a = 9;
b = 4;
y = 5.0;
x = b / a;
The value of x after executing this code will be 0
This is because, both b and a are integers, so b/a yields integer division by default. Even though x is a double variable, the integer division of b/a returns 0 instead of 0.44. If you want to do this correctly, you will need to cast the result of b/a into double. That is changing x=b/a; into x=(double)b/a; in that case, the value of x will be 0.4444
Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Get Answers For Free
Most questions answered within 1 hours.