November 2013
Beginner
325 pages
9h 47m
English
Every function can have local variables. Local variables are variables declared inside a function. They exist only during the execution of that function and can only be accessed from within that function. For example, consider a function that computed how long to cook a turkey. It might look like this:
void showCookTimeForTurkey(int pounds)
{
int necessaryMinutes = 15 + 15 * pounds;
printf("Cook for %d minutes.\n", necessaryMinutes);
}
necessaryMinutes is a local variable. It will come into existence when showCookTimeForTurkey() starts to execute and will cease to exist once that function completes execution. The parameter of the function, pounds, is also a local variable. A parameter is ...
Read now
Unlock full access