TCS
Company
Programming
Program
why do n++ execute faster than n=n+1 in c language
Read Solution (Total 9)
-
- It is because n=n+1 will execute the ADD instruction that requires two memory reference cycles
But for n++ it will execute the INC instruction that will require only one such cycle
So, n++ executes faster - 10 years agoHelpfull: Yes(27) No(0)
- may be because in N++ there is only one operation to be performed, i.e., to increment N. But in N=N=1, There are 2 operations being performed which are arithmetic addition of 1 with N and then assignment of this to the variable N.
- 10 years agoHelpfull: Yes(3) No(0)
- it is due to operator precedence
- 10 years agoHelpfull: Yes(3) No(0)
- because n=n+1 is a arithmetic operation in which 1 is added to n and then the value of n is changed.. but in n++ simply it is incremented by 1..
- 10 years agoHelpfull: Yes(1) No(0)
- this is coz n++ takes the value of another location rapidly by its increment operator as increment operator is defined in libary files
and in n=n+1; first variable takes an adrress in memory location and then the value is added with 1 so its take time while execution. - 10 years agoHelpfull: Yes(0) No(0)
- unary operations are performed than binary operations
- 10 years agoHelpfull: Yes(0) No(0)
- 1 should be first converted into its ascii value then into its binary then added,
but if we increment it add 00000000000001 directly so is the reason - 9 years agoHelpfull: Yes(0) No(0)
- n++ requires a single machine instruction while n+1 requires more no. of instructions.
- 6 years agoHelpfull: Yes(0) No(0)
- for the n++ it require 2 memory access and the n=n+1 require the 3 memory acess so n=n+1 get slow
- 5 years agoHelpfull: Yes(0) No(0)
TCS Other Question