0
Can anyone explain better the difference and the reason of 'x++' and '++x' to me?
I understand that 'x++' is adding to 'x' by 1 correct? I had to come back here from the next section even because it is just a bit strange to me...
8 Respostas
+ 5
int y;
int x;
//posfix, first assign x value to y.
after x is incremented.
x = 0;
y = x++;
Console.WriteLine(y); //output 0
//prefix, first x is incremented,
after assign x value to y.
x = 0;
y = ++x;
Console.WriteLine(y); //output 1
+ 3
both method add +1 to x. but using x++ you can use the original value before add +1 to x.
+ 1
x++ // Uses the variable and then adds one.
++x // Adds one to the variable and then uses it.
0
Would you be able to say 'x++' includes x, whereas '++x' does not?
0
its either im dumb for not understanding this only...or im just dumb...:/
0
int y;
int x;
printf("Enter integers:\n");
scanf("%d", &y);
for(x=0;x<5;x++)
return 0;
0
For x++ the value of x is assigned first and then it is incremented by 1;;;;but where as coming to ++x the value of x is incremented firstly and then the value is assigned to x;;;;;;
Ex::: int x=3;
X++=3+1=4
++x=1+3=4
- 1
if you have two variables, var1 & var2.
if var1=9
var2=var1++
assign 9 to var2, then increment var1=10
var2=++var1
var1 is10, then increment var2=10