-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-FunctionsinCpp.cpp
More file actions
31 lines (23 loc) · 911 Bytes
/
2-FunctionsinCpp.cpp
File metadata and controls
31 lines (23 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Functions in C++
Functions are not of a class
Functinos that are part of a class are called Methods
EXAMPLE of a function:
int Multiply(int a, int b)
{
return a * b
}
int Multiply()
{
return 2 * 5
}
void Multiply(int a, int b)
{
std::cout << 5 * 8 << std::endl;
}
Call a function:
int result = Multiply (3,2);
The COMPILER can INLINE the function or can just keep them in another part of the code and jump there when it needs. INLINING makes the program faster.
If a function has a retunr value, it has to return a value: only the main function can return nothing, it will assume you are returning 0
function DECLARATION: is the DEFINITION with only the HEADER of the function
DEFINITION contains the Header and the Body of the function
DECLARATIONS are in the Header file and when you include an header file, the compiler just copy/paste all the contenue of the file header at the include line.