Thread: why the difference?

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 06: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, 05:20 AM