Memory Allocation is a bit tricky, but it's easier than you think. It is, as the name implies, the usage and selection of data to optimize program function and speed. Basically, Memory Allocation is a "perk" of languages such as C/C++ that allow programmers to only use EXACTLY as much data as needed, freeing up memory for other computer functions.
Some good info to know about memory...
- memory is known in "bytes", these are 8-bit "groups" of data.
- A "bit" is a value that is either 0 or 1.
Variable sizes:
- Char: 1 byte
- Int: 4 bytes
- double: 8 bytes
When neighboring elements are of the same type (for example, an array of chars), they will have a difference in address that increments/decrements by the value of the memory size.
Since a char variable has a size of 1 byte, neighboring elements will have addresses that differ by 1.
Ex: char addresses: 1204, 1205, 1206, 1207... (1 byte)
int addresses: 1204, 1208, 1212, 1216... (4 bytes)
foois a character array and as such has the same size as any other array since it's essentially just a pointer.