What is the execution sequence for the code (x = i++ + ++i) ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robertcullen
    New Member
    • Aug 2010
    • 4

    #1

    What is the execution sequence for the code (x = i++ + ++i) ?

    main()
    {
    int i=1;
    int x;
    x=i++ + ++i;
    printf("%d",x);
    }
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Strange how this question has arisen so many times recently. Look here and here and here.

    Comment

    • robertcullen
      New Member
      • Aug 2010
      • 4

      #3
      I want to know how compiler compile this code?
      In which sequence it is going to execute.
      firstly "i++" or "++i".
      Its Associativity?

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        This is a trick question; nobody can answer it. The explanation is in those links I gave you in my first reply.

        I'm curious why you're asking about this.

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          I suggest it is clever question set by a tutor as an assignment,
          to test the students understanding of compiler logic.

          So an explanation of why it is impossible to answer is what the tutor is looking for.

          Comment

          Working...