GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 426 of 436    Print  
Does ++p faster than p++?

  
Total Answers and Comments: 2 Last Update: July 31, 2008     Asked by: janhavibend 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Jaya_Kaja
 

Between ++p & p++ , there is no diff in terms of speed of execution .because both are of unary . But there is a diff in the evaluation of an expression by using these unary operations.

++p - First the value of p gets incremented by one & then the incremented value will be used in the expression for further evaluation.
p++ - First the value of p is used in the expression & then the value of p will get incremented by one .

For eg :

a) p= 10;
val = ++p * 100 ;
Here val = 1100;
p = 11;

b) p=10;
val = p++ * 100;
Here val = 1000;
p =11;

- Jayalakshmi Kaja



Above answer was rated as good by the following members:
sourabh_t
July 21, 2008 04:53:13   #1  
decentswati Member Since: July 2008   Contribution: 1    

RE: Does ++p faster than p++?

++p is faster as the implementation of p++ will have extra execution cycles for returning the previous memory location reference in addition to the incrementing of value.


 
Is this answer useful? Yes | No
July 28, 2008 14:47:28   #2  
Jaya_Kaja Member Since: July 2008   Contribution: 3    

RE: Does ++p faster than p++?

Between ++p & p++ , there is no diff in terms of speed of execution .because both are of unary . But there is a diff in the evaluation of an expression by using these unary operations.

++p - First the value of p gets incremented by one & then the incremented value will be used in the expression for further evaluation.
p++ - First the value of p is used in the expression & then the value of p will get incremented by one .

For eg :

a) p= 10;


val = ++p * 100 ;

Here val = 1100;

p = 11;

b) p=10;
val = p++ * 100;
Here val = 1000;
p =11;

- Jayalakshmi Kaja


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster. There are several restrictions 
Latest Answer : If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access ...

The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the 

A binary search, such as bsearch() performs, is much faster than a linear search. A hashing algorithm can provide even faster searching. One particularly interesting and fast method for searching is to 
Latest Answer : quick short method is a best one ...

The answer depends on the situation you are writing code for. Macros have the distinct advantage of being more efficient (and faster) than functions, because their corresponding code is inserted directly 

The heap is where malloc(), calloc(), and realloc() get memory. Getting memory from the heap is much slower than getting it from the stack. On the other hand, the heap is much more flexible than the stack. 

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. 
Latest Answer : n++ takes more than one instruction, ++n is faster. n++ has to store n, increment the variable and return n, while ++n increment n and return without storing the previous value of n. ...

Explain why p++ is faster than p+1? 
Latest Answer : static memory allocation :the memory allocation is done at the time of compilation itself..it is known as static because this allocation cannot be changed is less memory or more memory is needed at the time of execution of program...in this type good ...

Latest Answer : Between ++p & p++ , there is no diff in terms of speed of execution .because both are of unary . But there is a diff in the evaluation of an expression by using these unary operations.++p - First the value of p gets incremented by one & then ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.  By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.  IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape