I can't seem to figure out the following expression with mixed data types:
Code:
int i = 10, j = 7;
unsigned int k;
double q = 3.56;
char c;
k = q * i - (2 * i) / j;
printf("k = %d\n", k);
c evaluates this to:
33 i re-checked using googles calculator and i'm getting
(3.56 * 10) - ((2 * i) / 7) = 35.6 - 0.285714286 i
Is it because it's rounded off somehow ?
next:
Code:
c = q * i * j;
printf("c = %d\n", c);
this is even more confusing correct me if i'm wrong the answer should be:
3.56 * 10 * 7 = 249.2
but C again, evaluates it to -7
finally,
Code:
k = -(i * q);
printf("k = %d\n", k);
All these expressions are in the main function so "k" stores the previously evaluated expression 33
so 33 - (10 * 3.56) = -2.6
but C, again does not seem to agree:
k = -35