Showing posts with label integer truncation error in c. Show all posts
Showing posts with label integer truncation error in c. Show all posts

Tuesday, 21 April 2015

Integer Truncation Error in C

the integer truncation error is displayed using the following simple program

void main(){
int a = 5;
int b = a/2;
int c = b*2;
printf("integer truncation error in C\n");
printf("the value of a is %d\n",a);
printf("the value of b = a\\2 is %d\n",b);
printf("the value of c = b*2 is %d\n",c);
getch();
}


and the output is
integer_truncation

which displays the result of (5/2)*2 = 4 which is wrong.