+ 18
Which is more efficient n=n+1 or n++?
Whats the major difference between these statements as both of them do the same operations.
52 Respostas
+ 23
The second has two characters less.
+ 12
Most compilers optimizes the code you write, and those two will generate the same assembly code. In that case, it would be more efficient to just write n++ or ++n than n=n+1.
+ 9
Modern compilers generate the same assembly code hence practically its no difference, since its just an INC instruction.
+ 5
Since the compiler selects the most efficient route of execution, the n=n+1 would be automatically converted to n++. There is no real difference between these as far as the compiler is concerned.
+ 4
Both are same.... in terms of efficiency as both statements can be considered as having constant time complexity...
+ 3
AFAIK n++.... Since there is increment and reassignment in n=n+1
+ 2
both are the same but n++ is easy to write
+ 2
They are the same but you should be careful about pre and post increment
+ 2
With: n++ ;
You write less code and I think it's more intelligent way of code. šš
+ 2
n++ is more efficient bcoz there is least time to load, compile & output.
+ 2
n++
+ 2
According to 'c' and 'c++' pre and post decrement or increment operator is good because it feels handy with program
Many languages does not support 'n++' type of format like python..,we have to take care about themš
+ 2
n++ Better then the other
+ 2
As it takes less space
+ 2
N=N+1 is efficient
+ 1
You could also compare them with n+=1
+ 1
both are same but n++ is better
+ 1
n++ is most usefull and easy
+ 1
n++
+ 1
++n is the good habit to using in programming