Increment and decrement operators

+1 ♦Avishka RJ ♦™ · February 10, 2015

#include 

using namespace std;

int main()
{
    int x =15 ;
    cout
Friends, When I typed this code it gives 15 , 15 , 15 , 16. 
How it happened ?? can you explain it (it's little bit confusing to me)

Post a Reply

Replies

Oldest  Newest  Rating
+2 Alf Nohr · February 11, 2015
x = x + 1;

Is the same as 

x++;

&
x = x - 1;

is the same as

x--;


 
but you can get a more detailed description here: :)
http://www.tutorialspoint.com/cplusplus/cpp_increment_decrement_operators.htm
0 Alf Nohr · February 10, 2015
Could you post the whole code? :)
0 ♦Avishka RJ ♦™ · February 11, 2015
ooops , Sorry something has happened when i post it .see below
0 ♦Avishka RJ ♦™ · February 11, 2015
#include <iostream>

using namespace std;

int main()
{
    int x =15 ;
    cout<<--x<<"  "<< ++x <<endl ;
    cout << x++ << endl;
    cout << x << endl;
    return 0;

}
  • 1

C++

106,985 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator