++x and x=x+1 aren't equal?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

++x and x=x+1 aren't equal??

14th Jun 2016, 2:30 AM
priyanka
9 Answers
+ 1
yes is equal, the first exp is the most compact while the second exp is complete
14th Jun 2016, 8:51 PM
Tommaso
+ 1
++x will increase and then consider the expression but it not with the case of x+=1
16th Jun 2016, 4:50 AM
Nisarg Uchiha
Nisarg Uchiha - avatar
0
that depends on the way it used.
14th Jun 2016, 3:07 AM
Jarin P
Jarin P - avatar
0
Depends, how you use them.
14th Jun 2016, 4:18 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
0
they are equal but there is a different between preincrement and postincrement
14th Jun 2016, 9:30 AM
Sardor
Sardor - avatar
0
x++ and x+=1 are not equal while printing, but ++x and x+=1 are equal
18th Jun 2016, 7:16 AM
Vivek Sharma
Vivek Sharma - avatar
0
++i or i++or i=i+1 or i+=1 have the same practical effect "in a bubble", by that I mean that you can use them interchangeably if you're not assigning i+1 to any other variable, or using i+1 on the same line where you increment i. the difference between i++ and ++i is that ++i increments first, then uses the new value, and i++ does the opposite. there others have the same effect regardless of how you write them.
20th Jun 2016, 7:35 AM
Matheus Fernandes
Matheus Fernandes - avatar
0
on another note, both for(i=0;i<5;i++) and for(i=0;i<5;++i) have the same effect, but b=i++; does not have the same effect as b=++i;
20th Jun 2016, 7:37 AM
Matheus Fernandes
Matheus Fernandes - avatar
- 2
Both are same, but while printing it makes lot of difference.
14th Jun 2016, 6:38 PM
Naveen