Jump to content
Posted 09 October 2008 - 11:41 AM
Posted 09 October 2008 - 06:30 PM
Posted 10 October 2008 - 03:19 AM
I'm not sure I quite understand what you mean but I will explain the difference between passing by value and passing by reference.
What is the difference in passing a reference and passing a pointer and passing by reference?
A copy of numberGuessed is pushed onto the stack. The function may modify this copy, but the original stays the same. Hence, numberGuessed is always false.
guessRun(userNumber, chosenNumber, numberGuessed);
You are passing the address of the original. This means that you can access the original by using that address:
guessRun(userNumber, chosenNumber, &numberGuessed);
And this will actually modify the original, causing the effect that you want.
*numberGuessed = true;
Posted 12 October 2008 - 08:26 PM
Edited by strangerdanger, 12 October 2008 - 10:20 PM.
Posted 13 October 2008 - 03:49 PM
0 members, 0 guests, 0 anonymous users