Changes

An Overview of Objective-C Functions

7 bytes removed, 14:30, 13 December 2010
no edit summary
== Static Variables in Functions ==
In the normal course of program execution, any variables declared locally in a function are discarded when the function exits and execution returns to the code location from where the call was made. For example, each time the ''displayit'' function is called in the following code, variable ''jy'' is re-initialized to 0:
<pre>
void displayit (int i)
{
static int y = 0;
y += i;
</pre>
If we want the value of ''jy'' to be retained after the function has executed, we simply declare the variable as ''static'':
<pre>
</pre>
Now, when the code is compiled and run, we get the following output because the value of ''jy'' is not being reset to 0 each time the function is called:
<pre>