Local variables, frames, and the stack

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 ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.