C Reference Cheat Sheet Page 5

ADVERTISEMENT

C Reference Cheat Sheet
by
Ashlyn Black
via
Functions
Functions (cont)
Declaring
Returning an array/string/structure by pointer.
type f(){ static
The static qualifier is necessary otherwise
type x[]; return
type/void funcName([args...]){ [return var;] }
x won't exist after the function exits.
&x; }
Function names follow the same restrictions as variable names but must
Passing by pointer allows you to change the originating variable within the
also be unique.
function.
Return value type (void if none.)
type/void
Scope
Function name and argument parenthesis.
funcName()
int f(){ int i = 0; } i++; 
Argument types & names (void if none.)
args...
i is declared inside f(), it doesn't exist outside that function.
Function content delimi​ t ers.
{}
Prototyping
Value to return to function call origin. Skip for void
return var;
type funcName(args...);
type functions. Functions exit immediately after a
Place before declaring or referencing respective function (usually before
return.
main.)
By Value vs By Pointer
Same type, name and args... as
type
Passing variable y to function f argument x (by
void f(type
respective function.
funcName([args...])
value.)
x); f(y);
Semicolon instead of function delimiters.
;
Passing an array/string to function f argument x (by
void f(type
pointer.)
*x);
main()
f(array);
int main(int argc, char *argv[]){return int;}
Passing a structure to function f argument x (by
void f(type
pointer.)
Anatomy
*x);
f(structure);
Program entry point.
int main
Passing variable y to function f argument x (by
void f(type
# of command line arguments.
int argc
pointer.)
*x); f( &y);
Command line arguments in an array of strings. #1 is
char *argv[]
Returning by value.
always the program filename.
type f(){
return x; }
Exit status (inte​ g er) returned to the OS upon
return int;
program exit.
Returning a variable by pointer.
type f(){ type
Command Line Arguments
x; return &x;
}
Three arguments, "ap​ p ", "tw​ o " and "3".
app two 3
Two arguments, "ap​ p " and "two 3".
app "two 3"
main is the first function called when the program executes.
By Ashlyn Black
Published 28th January, 2015.
Sponsored by
Last updated 20th April, 2015.
Measure your website readability!
Page 5 of 13.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education