Increment and decrement

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// practice 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include<vector>
using namespace std;
int main()
{
	int i=1;
	int j=2;
	    i=++j;
		j=i++;

	cout<<i<<j<<endl;
}


Hello all,I am new to c++,I just have a small query when i tried to cout the result it giving 4 and 3.But actually it has to give 3 and 3 right ?
Pre-increment increases the value first and then returns the result.
Post-increment increases the value, but returns a copy of the original value.
ya as you said,here in case of i =3 because j is increased to 3 as original value of j is 2.And i=3 because the copy of original value is 3 right ? please help me.
Hi there,

This answer is pretty clear: http://stackoverflow.com/a/4706225

Hope that helps.

All the best,
NwN
Thanks for the help NWN i understood it now !
Topic archived. No new replies allowed.