Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why ++++i works and i++++ does not work?

Why ++++i works and i++++ does not work?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Don Box
    wrote on last edited by
    #1

    Hi all. I'm having this problem and really not getting, what is happening behind the hood. Plzz help me out in this regard. This is basic C concept.

    void main ()
    {
    int i = 0;
    ++++i; //WORKS
    i++++; //DOESN'T WORK
    }

    In the above code, ++++i (Pre-Increment) works but i++++ (Post-Increment) doesn't work. What could be the reason? Plzz explain in detail. Any Help is appreciated.

    C S D G 4 Replies Last reply
    0
    • D Don Box

      Hi all. I'm having this problem and really not getting, what is happening behind the hood. Plzz help me out in this regard. This is basic C concept.

      void main ()
      {
      int i = 0;
      ++++i; //WORKS
      i++++; //DOESN'T WORK
      }

      In the above code, ++++i (Pre-Increment) works but i++++ (Post-Increment) doesn't work. What could be the reason? Plzz explain in detail. Any Help is appreciated.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Because left to righ operator associativity. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      1 Reply Last reply
      0
      • D Don Box

        Hi all. I'm having this problem and really not getting, what is happening behind the hood. Plzz help me out in this regard. This is basic C concept.

        void main ()
        {
        int i = 0;
        ++++i; //WORKS
        i++++; //DOESN'T WORK
        }

        In the above code, ++++i (Pre-Increment) works but i++++ (Post-Increment) doesn't work. What could be the reason? Plzz explain in detail. Any Help is appreciated.

        S Offline
        S Offline
        ShilpiP
        wrote on last edited by
        #3

        Click here[^]

        Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

        1 Reply Last reply
        0
        • D Don Box

          Hi all. I'm having this problem and really not getting, what is happening behind the hood. Plzz help me out in this regard. This is basic C concept.

          void main ()
          {
          int i = 0;
          ++++i; //WORKS
          i++++; //DOESN'T WORK
          }

          In the above code, ++++i (Pre-Increment) works but i++++ (Post-Increment) doesn't work. What could be the reason? Plzz explain in detail. Any Help is appreciated.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Don Box wrote:

          i++++; //DOESN'T WORK

          The second pair of "++" needs an l-value to operator on, which "i++" is not.

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          1 Reply Last reply
          0
          • D Don Box

            Hi all. I'm having this problem and really not getting, what is happening behind the hood. Plzz help me out in this regard. This is basic C concept.

            void main ()
            {
            int i = 0;
            ++++i; //WORKS
            i++++; //DOESN'T WORK
            }

            In the above code, ++++i (Pre-Increment) works but i++++ (Post-Increment) doesn't work. What could be the reason? Plzz explain in detail. Any Help is appreciated.

            G Offline
            G Offline
            Gregory Bryant
            wrote on last edited by
            #5

            #include int main() { int i = 0; while(i<5) { std::cout << i; i++; } /* while(i<5) { std::cout << i; ++i; } */ std::cout << std::endl; std::cin >> i; return 0; }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups