In this program j, a value of 2 is assigned.
j = 2 * 3 / 4 + 2.0 / 5 + 8/5;
but if the same expression is calculated using a calculator, it will be equal to 3.5, so in an integer expression it will become equal to 3.
I want to ask why is jassigned 2? What am I missing?
C:
#include <stdio.h>
int main()
{
int i,j,k=0;
int line=0;
j = 2 * 3 / 4 + 2.0 / 5 + 8/5;
printf(" %d --------- \n", j);
k -= --j;
printf(" %d --------- \n", k);
for(i=0;i<5;i++)
{
switch(i+k)
{
case 1:
case 2:
printf("\n %d", i+k);
line++;
case 3:
printf("\n %d", i+k);
line++;
default:
printf("\n %d", i+k);
line++;
}
}
printf("\n %d", line);
return 0;
}
Output:
2 ---------
-1 ---------
-1
0
1
1
1
2
2
2
3
3
10
source
share