Sponsored Links

Interview Questions



INTERVIEW QUESTIONS C BRANCHES & LOOPS IN C DETAILS

Question: why n++ executes faster than n+1?


Answer: 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.

Category Branches & Loops in C Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.3) By 8871 users
Added on 7/19/2011
Views 77815
Rate it!

Question: why n++ executes faster than n+1?




Answer:

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. Source: CoolInterview.com


The question is meaningless since the two aren't equivalent.

n++ modifies n.
n+1 does not.

If the purpose is to increment n by one and n is a register variable, the two are almost the same in processor resources, except that the result of n+1 requires the compiler to allocate a second register for the intermediate result.

Also, the first answer is incorrect. The 'INC EAX' instruction in an x86 CPU is no faster than an 'ADD EAX,1' instruction and the only benefit is to reduce code space. Source: CoolInterview.com

Answered by: Joel Corley | Date: | Contact Joel Corley Contact Joel Corley

Memory related operations takes more time in m+1 it goes to the memory twice ie to search and to store whereas m++ goes only once Source: CoolInterview.com

Answered by: imran | Date: 9/3/2007 8:42:22 AM | Contact imran Contact imran

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 question is meaningless since the two aren't equivalent.

n++ modifies n.
n+1 does not.

Source: CoolInterview.com

Answered by: alekh | Date: 4/10/2009 | Contact alekh Contact alekh

Well, it does not!
While we might be tempted to say that 'increment' instruction executes faster than a 'sum' instruction, I have not come across any compiler which uses 'sum' instruction for 'k+1'.
Also, this issue is totally dependent upon the instruction set of the machine (and compiler) for which the code is compiled. So, there is no point in making it a general rule. Source: CoolInterview.com

Answered by: Nileshkumar | Date: 8/22/2009 | Contact Nileshkumar Contact Nileshkumar

n++ is unary operation and n+1 is binary operation.unary operation takes less time than binary operation.that is why n++ is faster than n+1 Source: CoolInterview.com

Answered by: sereena | Date: 9/29/2009 | Contact sereena Contact sereena

n++ requires less memory as compared to n+1 as well as n++ requires just 1 reg bt n+1 requires one more register to store the answer Source: CoolInterview.com

Answered by: astha patni | Date: 11/1/2009 | Contact astha patni Contact astha patni

hi..
n++
and n+=1 both will give the same results but when you compile these instructions seperately, compliler will generate only INR for n++ and
for n += 1 will generate ADD instruction . So this INR instruction is run little smaller than ADD. Source: CoolInterview.com

Answered by: shivanand | Date: 1/10/2010 | Contact shivanand Contact shivanand

n++ executes fast then n+1 because n++ takes less machine cycles than n+1. Source: CoolInterview.com

Answered by: sivaganesh | Date: 2/23/2010 | Contact sivaganesh Contact sivaganesh

++ is a unary operator while + is a binary operator...
Tecnically speakin, A unary operator works on only one operand...while the binary works on two...this affects the execution time...More the operands...more will be the time of execution... Source: CoolInterview.com

Answered by: Pinki Ruparel | Date: 3/4/2010 | Contact Pinki Ruparel Contact Pinki Ruparel

n++ is faster because of the following reasons:

1 simply,n++ is a unary operator and n+1 is a binary operator. unary operator takes less time than binary operator.
2 n++ requires less memory place and n+1 requires more. Source: CoolInterview.com

Answered by: raghul krishnan | Date: 3/24/2010 | Contact raghul krishnan Contact raghul krishnan

It's totally Machine dependent or compiler dependent. Source: CoolInterview.com

Answered by: Hitesh | Date: 3/25/2010 | Contact Hitesh Contact Hitesh

what is the out put of a+~b Source: CoolInterview.com

Answered by: akash patil | Date: 5/21/2010 | Contact akash patil Contact akash patil

Any modern compiler will optimise n=n+1 to n++ Source: CoolInterview.com

Answered by: nico | Date: 5/21/2010 | Contact nico Contact nico

n++ is executed more faster the n+1 because the pointer pointing to location n is incremented very easily where as for n+1 the control has to mov to the alu unit and the back to the n location. Source: CoolInterview.com

Answered by: krupa | Date: 6/19/2010 | Contact krupa Contact krupa

n++ operator is unary which takes less time to executed as compared to n+1 which is binary operator Source: CoolInterview.com

Answered by: Anil R Chinchawade | Date: 6/23/2010 | Contact Anil R Chinchawade Contact Anil R Chinchawade

generally unary operators executes fast.
and n+1, here it needs to perform both increment and assignmentdone seperatly.where as in n++ both are done at a time Source: CoolInterview.com

Answered by: sriman bhuma | Date: 7/1/2010 | Contact sriman bhuma Contact sriman bhuma

n++ is a single instruction set but n+1 is a multiple instruction set ,so n++ executes faster then n+1. Source: CoolInterview.com

Answered by: saroj | Date: 7/2/2010 | Contact saroj Contact saroj

n++ requires an INC command in assembly
n+1 requires following commands -
MOV R1,1
ADD R1,N
Hence n++ is slow than n+1 as n++ uses only one instruction an n+1 uses two instruction Source: CoolInterview.com

Answered by: saud | Date: 7/5/2010 | Contact saud Contact saud


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
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
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}


else
View Answer
x) main()
{
printf("%x",-1<<4);
}


}


- Branches & Loops in C Interview Questions & Answers"> View Answer
How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....)

View Answer
Can include files be nested?
View Answer
Is NULL always defined as 0?
View Answer
Which expression always return true? Which always return false?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Branches & Loops in C Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2025 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions