
- Forum
- Programming Talk
- C and C++
- Amazing Output
Amazing Output
This is a discussion on Amazing Output within the C and C++ forums, part of the Programming Talk category; I thought the answer to this C program would be 2 #include <stdio.h> main() { int i; i=-4/8*-5 printf("%d",i); } ...
-
Amazing Output
I thought the answer to this C program would be 2
#include <stdio.h>
main()
{
int i;
i=-4/8*-5
printf("%d",i);
}
But it is not so. The output was zero. Why is it so? Can someone explain the reason for the same?
-
The output you have got is absolutely right. This is because in the expression i=-4/8*-5
-4/8 since both are integers the division gives the integer value as 0 and so
i=0*-5=0 which is the output you have got.
Thumb rule is while you do operation with a integer and another integer the result is always a integer.

Reply With Quote





