Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incrementing variables clarification needed!

Status
Not open for further replies.

pghsteelers

Technical User
Apr 21, 2006
121
0
0
US
I understand the general explanation of the expression variable++ or ++variable as in when the variable is incremented during the carring out of an expression. However, can someone clarify how it occurs when being passed as a parameter in a function such as:

y = functionName(var1, ++var2);

as apposed to

y = functionName(var1, var2++);
...
...
...
int functionName(int var1, int var2)
{
sum = var1 + var2;
return sum;
}


Thanks in advance
 
Wow, nice site. I think I will be implementing a reading(or two) from this site everyday.
 
If you want to avoid confusion, just call the function and increment the variable on two separate lines. There is no increase in compiled efficiency by putting it in a single statement; it merely saves you a few keystrokes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top