increment operator syntax

This is a discussion on increment operator syntax within the C++ Programming forums, part of the General Programming Boards category; Hello all, New to the forum and C++. I am not entirely clear on the proper usage of increment operators. ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    9

    increment operator syntax

    Hello all,

    New to the forum and C++. I am not entirely clear on the proper usage of increment operators.

    What means x = x +1?

    x++

    or

    ++x?

    Also, which one means "get current value of x"?

    thank you so much in advanced

    spark*

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,648
    Quote Originally Posted by spark*
    New to the forum and C++. I am not entirely clear on the proper usage of increment operators.

    What means x = x +1?

    x++

    or

    ++x?
    If you use them as stand-alone statements: both. Otherwise: neither.

    Quote Originally Posted by spark*
    Also, which one means "get current value of x"?
    Neither. If you want x, write x. However, if you are using an increment operator in a larger expression and want the current value of x, then post-increment (x++) makes sense.
    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
    Mar 2012
    Posts
    9
    Hey laserlight!

    Got it.. Thanks for clearing that up!

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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