We will now explore how the concept of pointers (addresses) can be used to modify the value of a variable inside a function, despite the fact that the variable’s scope does not extend to that function.
If you cannot see this codecast, please click here.
Check Your UnderstandingCheck Your Understanding
1.
You want to write a function that increases the integer value stored in a variable num by one. Given the following function definition, what is the correct function call? Assume that a variable num of type int has been declared and initialized.
void increasebyone(int *a)
{
*a = *a + 1;
}
Feel free to use the window below to try out some code. Be sure to work the correct answer out "by hand" first before verifying your answer using the code window.