If you’ve run into the classic noob C programmer’s problem of “Why won’t my function update my variable?” then you might have resorted to using a global variable instead of passing the variable into the function as a parameter. Global variables allow ‘write access’ to number from both the caller and the callee, like this,

but global variables are considered bad for lots of reasons. Not least of which is that your function can no longer double anything other than your specific number.

Instead you need to pass number into doubleIt as a pointer parameter.

Mike

Leave a Reply

Your email address will not be published. Required fields are marked *