Thread: doubt over Increment and addition operator

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    4

    doubt over Increment and addition operator

    Hi All,
    When I execute the below code Im getting the value of a as 5 and y as 10. can anyone please explain why the value of y is printed as 10.

    Code:
    void main()
     {
        int a=3,y;
        y= ++a + ++a;
        printf("a %d y %d",a,y);
     }
    o/p:
    a 5 y 10
    

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pre-increment operator..
    By narendrav in forum C Programming
    Replies: 6
    Last Post: 05-02-2013, 01:57 AM
  2. Increment operator
    By ssharish2005 in forum C Programming
    Replies: 8
    Last Post: 06-06-2011, 04:32 PM
  3. Increment Operator
    By theunderdog118 in forum C Programming
    Replies: 4
    Last Post: 05-31-2010, 11:00 AM
  4. Increment Operator
    By anirban in forum C Programming
    Replies: 5
    Last Post: 11-25-2008, 08:25 AM
  5. Help with increment operator
    By capvirgo in forum C Programming
    Replies: 2
    Last Post: 02-18-2008, 11:06 PM

Tags for this Thread