Category:C: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) m (→Curly Braces) |
Puppydrum64 (talk | contribs) m (→Functions) |
||
Line 69: | Line 69: | ||
//procedure whose outcome does not need to be measured or remembered later.</lang> |
//procedure whose outcome does not need to be measured or remembered later.</lang> |
||
Note that the variable names listed as arguments when declaring a function are |
Note that the variable names listed as arguments when declaring a function are known as <i>formal parameters</i> and only are there to define the function. Variables with those names need not be declared or defined in your actual function, nor do they refer to any variables in your program that happen to have the same name. Essentially, formal parameters act as placeholders for the actual function parameters that you'll be using. |
||
<lang C>int foo(int x){ |
<lang C>int foo(int x){ |
||
return x; |
return x; |
||
} // "x" doesn't need to be a variable in your real program. If it is, that's not related in any way to the "x" here. |
|||
} // the "x" here is just a placeholder for whatever actually goes in when you invoke foo. |
|||
int main() |
int main() |
||
Line 80: | Line 80: | ||
int z = 2; |
int z = 2; |
||
y = foo(z); //note that x was never involved. That's because the "x" earlier was |
y = foo(z); //note that x was never involved. That's because the "x" earlier was the formal parameter. |
||
}</lang> |
}</lang> |