Switch to full style
C++ code examples
Post a reply

C++ Increment Operators

Thu Nov 13, 2008 1:51 pm

Increment operator in C++
cpp code
#include <stdio.h>

int main()
{
int m = 10;
int n = 5;

m *= n - 3;
printf("%d\n", m);

n = ++m;
printf("%d %d\n", n, m);

n = m++;
printf("%d %d\n", n, m);

n = --m;
printf("%d %d\n", ++n, m);

n = m;
m--;
--n;
printf("%d %d\n", n, m);
}


Code:
++x: Returns the new value of x.

x++: Returns the old value of x.


There is only a difference when the return value is used:
  • x++; and ++x; are the same.
  • Increment operators are similar to Java.
  • Things like x + ++x are not well-defined in C.
  • In the context of C, increments are better able to create bizarre programs.




Post a reply
  Related Posts  to : C++ Increment Operators
 How To Increment Date In JSP?     -  
 PHP operators     -  
 difference between the >> and >>> operators     -  
 Bitwise operators     -  
 using bit-wise operators in c++     -  
 Equality Operators     -  
 shortcut operators     -  
 Using Assignment Operators     -  
 bitwise operators usage in C++     -  
 Comparison Operators in java     -  

Topic Tags

C++ Basics