CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
Why n++ executes faster than n+1?
Category C Interview Questions
Rating (4.0) By 6 users
Added on 10/22/2004
Views 5999
Rate it!
Answers:

The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation.



The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation.<br>If n+1 is executed,the value of n should be stored in memory,then bring to CPU and perform addition in CPU and then write to memory back.Hence,CPU time is consumed more.<br>Compilers nowadays are smarter,if it encounters n+1,it replaces it by n++.Hence,it really doesn't matters for user since optimization is gained by compiler.



 Posted by: Lohit.A.H    

Contact Lohit.A.H  Contact Lohit.A.H

n++ requires only to increment the value of n by one,while n=n+1 means first add 1 to the n and then perform the assignment operation =<br>thus it requires two tasks to be performed while n++ requires only one task to be performed.



 Posted by: abhay    

Contact abhay  Contact abhay

It depends on the target architecture. If the architecture does not support the INC/ DEC instruction, then n++ and n = n +1 will be same. Means, same kind of instruction will be generated.



 Posted by: anamika    

Contact anamika  Contact anamika

all high level lang are converted first to machine instruction and its the machine instruction on which the speed of execution of our program depend so n=1 means use of add instr of var and store value it it too time taking so we prefer n++ for faster execution.



 Posted by: Nishant jichkar    

Contact Nishant jichkar  Contact Nishant jichkar


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
Write the equivalent expression for x%8?
View Answer
Which expression always return true? Which always return false?
View Answer
What is storage class and what are storage variable ?
View Answer
What are the advantages of auto variables?
View Answer
Diffenentiate between an internal static and external static variable?
View Answer
What are advantages and disadvantages of external storage class?
View Answer
Differentiate between a linker and linkage?
View Answer
What are the characteristics of arrays in C?
View Answer
When does the compiler not implicitly generate the address of the first element of an array?
View Answer
What is modular programming?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/982/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.64