Exforsys
+ Reply to Thread
Results 1 to 2 of 2

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); } ...

  1. #1
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128

    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?


  2. #2
    caradoc is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    122
    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.


Latest Article

Network Security Risk Assessment and Measurement

Read More...