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=-...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To achieve Output | Ralph | Linux | 0 | 12-12-2006 03:58 AM |
| C Programming - Managing Input and Output Operations | JobHelper | Career Advice | 0 | 04-15-2006 08:30 AM |
| Controlling PHP Output: Caching and compressing dynamic pages | techguru | Unix Articles and Tutorials | 0 | 08-28-2005 11:26 AM |
| Solaris x86 FAQ 2/2 | Dan Anderson | Tech FAQ | 0 | 04-27-2004 08:24 PM |
| [gnu.bash.bug] BASH Frequently-Asked Questions (FAQ version 3.26) | Chet Ramey | Tech FAQ | 0 | 04-26-2004 11:00 AM |