+ 1
C++
x++ and ++x ... does someone have a piece of code to make sure i understood ? would be nice i m not sure to understand ><
5 Respuestas
+ 1
x++ first evaluates the expression with the previous value of x and than increment it. ++x on the other side, first increment x, then uses the updated value of it in the expression.
+ 1
int main()
{
int a,b;
a = 5;
b = a++;
cout << "b gets the value of a and than a is incremented by 1 \n a = " << a << " and b = " << b << endl;
a = 5;
b = ++a;
cout << "a is incremented by 1 and than b gets the value of a \n a = " << a << " and b = " << b << endl;
return 0;
}
+ 1
i++ always will be the last value declared for i ? and ++i = i+1 ? @ernaso kerbizi
+ 1
thanks eitan and ernaso, i got it :)
0
int i = 5;
cout << i++; //Outputs 5
cout << ++i; //Outputs 6