answersLogoWhite

0

++p increments p by 1 unit and returns the result. This is known as pre-increment.

int p = 0;

int q = ++p; // q=1, p=1.

This is effectively the same as saying:

int p = 0;

p = p + 1; // p= 1.

int q = p; // q = 1.

p++ also increments p by 1 unit, but returns the previous value of p, not the current value. This is known as post-increment.

int p = 0;

int q = p++; // q=0, p=1.

This is the same as saying:

int p = 0;

int q = p; // q = 0.

p = p + 1; // p = 1.

Of the two forms, ++p is marginally quicker because p++ employs a temporary variable for the return value, whereas ++p does not. As such, ++p is the preferred form for looping purposes:

for( int p=0; p<100; ++p);

Which version you use depends upon which value you want returned from the operator, whether it is the previous value or the new value.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What is the Difference between 9mm and 9mm p?

None. Actually, if you mean "+P" the plus P indicates more powder in the casing, therefore more velocity and more muzzle energy.


the difference between LT and P tires?

the difference between LT and P tires&rdquo; Topics: Tire Rack Wholesale


What is the difference between private stafford and plus student loans?

What is the difference between private stafford and plus student loans?


What is the difference between a turn and a twist?

spelling :P //I GOOGLE MO :P


Difference between step and terrace farming?

there's no difference between them as they both are done on slopes.. :) :P


What is the difference between pointers in c and c plus plus?

Nothing.


What is the difference between be plus ing and get plus ing?

There are no such terms in C++.


What is the difference between statements in c plus plus charconstp and char constp?

There is no difference. Both statements are invalid.


What is one third of difference between 6 and p is added to 8?

To find one third of the difference between 6 and ( p ), we first calculate the difference: ( 6 - p ). Then, one third of this difference is ( \frac{1}{3}(6 - p) ). When we add this to 8, the expression becomes ( 8 + \frac{1}{3}(6 - p) ). Thus, the final expression is ( 8 + \frac{6 - p}{3} ).


What is S P lag time?

the difference between the arrival of the p-wave and s-wave


What is the difference between a amplitude and a noise?

A,p[pdaokfpz'sJgfv';zsdv


Find the difference in cost between 12 articles is 3p each and 12 article at 5 p each?

The cost of 12 articles at 3 p each is 12 × 3 = 36 p. The cost of 12 articles at 5 p each is 12 × 5 = 60 p. The difference in cost between the two is 60 p - 36 p = 24 p. Thus, the difference in cost is 24 p.