why the difference?

This is a discussion on why the difference? within the C Programming forums, part of the General Programming Boards category; Code: void main() { int i=10,j; j=i++*i++; printf("%d",j) } o/p 100 void main() { int i=10; printf("%d",i++*i++); } o/p 110 ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    3

    Question why the difference?

    Code:
    void main()
    {
       int i=10,j;
       j=i++*i++;
       printf("%d",j)
    }
    
    
    o/p
    100
    
    
    void main()
    {
       int i=10;
       printf("%d",i++*i++);
    }
    
    
    o/p
    110
    
    
    why this o/p difference?anyone know?help me

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,888
    You are in the realm of undefined behaviour, as you read a variable twice in an expression where you also write it.

    Incidentally, you might want to read more about main().
    Last edited by laserlight; 05-20-2007 at 07:35 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    3
    thank you laselight for your answer and good advice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding the difference in two times
    By muthus in forum C++ Programming
    Replies: 4
    Last Post: 01-24-2008, 05:36 PM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. Replies: 6
    Last Post: 08-26-2006, 11:09 PM
  5. Difference between macro and pass by reference?
    By converge in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2002, 04:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21