Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My Script:

C++
int increment(int x)
{
  return x + 1;
}

void increment2(int *x)
{
  *x = *x + 1; 
}

int main(void)
{
  int count = 0;
  // call increment...
  // call increment2...
Posted
Updated 10-Dec-15 13:39pm
v3
Comments
Sergey Alexandrovich Kryukov 10-Dec-15 22:24pm    
Where do you see a script? C++ is not a scripting language.
—SA

1 solution

Increment takes an int as a param and returns an int, so count would go in, and be assigned to whatever came out

Increment2 is slightly different, it directly increments the int at the address it was passed (it should check for a NULL pointer), so you'd have to pass the address of count in

I can't make the explanation simpler than that without actually doing your homework for you :)
 
Share this answer
 
Comments
Member 12197225 10-Dec-15 19:43pm    
Thanks but i know what each one does as i wrote it. But I'm unsure on how to call them to increment the count without a loop....
barneyman 10-Dec-15 19:48pm    
the word 'loop' wasn't mentioned in your original question

you just call them ? they're functions .... it's a procedural language ...

Perhaps you've not outlined your *actual* requirement fully?
Member 12197225 10-Dec-15 19:49pm    
thanks. But I'm confused to how u call them
barneyman 10-Dec-15 20:25pm    
see my other comment down the thread ... google

i could give you a salmon, but you learning to fish is best
[no name] 10-Dec-15 19:43pm    
A 5. Maybe a hint to a Parameter ....(int&) would complete it ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900