Difference between revisions of "Function"

From Chilipedia
Jump to: navigation, search
(Function Calls)
Line 2: Line 2:
  
 
== Function Calls ==
 
== Function Calls ==
A function call in C++ generally looks something like this <code>obj.MyFunction( param1,param2 )</code>. It consists of the function name (<code>Myfunction</code> in the example above) followed parentheses () which surround parameters separated by commas (,). To call a member function of an object, you first type the object name, then a period '.', and then the function name (e.g. <code>obj.</code>).
+
A function call in C++ generally looks something like this <code>obj.MyFunction( param1,param2 )</code>. It consists of the function name (<code>Myfunction</code> in the example above) followed by parentheses () which surround parameters separated by commas (,). To call a member function of an object, you first type the object name, then a period '.', and then the function name (e.g. <code>obj.</code>).
  
 
The function parameters are used to control the behavior of the function. A function can have zero or more of these. A function can also return a value, which can be used in other operations. If a function does not return a value, its return type is <code>void</code>.
 
The function parameters are used to control the behavior of the function. A function can have zero or more of these. A function can also return a value, which can be used in other operations. If a function does not return a value, its return type is <code>void</code>.

Revision as of 13:35, 1 August 2016

A function is a grouping of code that you can invoke or 'call' from one or more points in your program. You can even call a function from itself (motherfucking funception)!

Function Calls

A function call in C++ generally looks something like this obj.MyFunction( param1,param2 ). It consists of the function name (Myfunction in the example above) followed by parentheses () which surround parameters separated by commas (,). To call a member function of an object, you first type the object name, then a period '.', and then the function name (e.g. obj.).

The function parameters are used to control the behavior of the function. A function can have zero or more of these. A function can also return a value, which can be used in other operations. If a function does not return a value, its return type is void.

Declaring and Defining Functions

Cumming soon ;)

What's really goin on here tho

What actually happens when a function is called is: the values to be passed to the function are placed somewhere where the function code can access them (called the stack, or in some calling conventions the parameters are put into CPU registers), then the current execution address is saved and the CPU jumps to the function address and begins executing the function instructions. At the end of the function, the result (if any) is placed in a predetermined location (typically a register), and the CPU jumps back to the address that it had previously saved and continues on its merry way.

Tutorial Videos

Beginner C++ Game Programming Tutorial 1

See Also

http://www.cplusplus.com/doc/tutorial/functions/