C and C++ General
Concepts
Declaration
Contains the function signature to let the compiler know what the function is (name, return type, params type and count)
int sum(int a, int b)
Parameter names are optional
This is correct too
int sum(int, int)
Definition
Contains the actual logic of the function. Can act as a [[#Declaration]] too, but need to be before calling it
int sum(int a, int b) {
return a + b;
}
Memory, Variables
int x; // This doesn't initialise the variable. It's data is whatever the previous program used it for. DO NOT USE it before setting it to a value
int y = 0; // This initialises the variable.
In general practice it's ok (?) to not initialize a variable but do not use it before setting a value to it.
Keywords
| Keywords | Notes | Link |
|---|---|---|
size_t |
Different OS might have different memory sizes. This makes sure that it uses the correct size. NOTE: If don't use it, might have integer overflow |