Exforsys

Online Training

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=-...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2007, 06:28 PM
Senior Member
 
Join Date: Apr 2006
Posts: 153
cyrus is on a distinguished road
Exclamation 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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-08-2007, 04:37 PM
Senior Member
 
Join Date: Apr 2006
Posts: 144
caradoc is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -4. The time now is 05:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.