A program written in C/C++, is compiled into a binary or executable file and stored on the hard disk. To do anything useful this executable file has to be loaded into a process by the operating system from where the microprocessor can execute it.
Once an executable has been loaded into a process, the processor will start executing its code from a well known entry point usually written as the one and only main function in our program. The process is given resources by the operating system which among other things consists of:
Stack Memory - To hold auto variables, function parameters and return values. When your code invokes a function, its parameters are pushed on to the stack, its return value is implicitly pushed on to the stack and its variables are also pushed on to the stack. The called function is now logically on top of the stack. When the function ends its local variables are popped of the stack and hence local variables are also called auto variable. The size of stack memory is limited and to hold larger collections of data, we use the heap.
Heap Memory - This memory can be allocated on demandfrom our program and used to the extent of RAM limit available in the system. A reference of the address location of memory allocated to our program has to be held and later passed on explicitly for deallocation to the runtime system. This is done through a mechanism called pointers.
File Handles - This memory is used to hold file handles of open files in our program in a file handle table.
Variables in our program may be classified as data variables and pointers. Data variables are created on the stack and their address is represented in our program as a variable name. The data is stored starting from the first byte of the location. The range of bytes used to store the data depends on the type of the variable.
Pointer variables are also created on the stack but they can only hold addresses of other variables which may be on the stack or on the heap. The data held at the location indicated by the pointer can be indirectly accessed using the pointer this is known as de-referencing the pointer.
Memory can be dynamically allocated to a pointer on the heap. The size of memory allocated depends on the data type of the pointer. the pointer will hold the address of the location as long as we require. When we finish with the memory allocated, we have to explicitly deallocate the pointer which results in the pointer holding an address at which our program no longer controls memory. We have to deinitialize the pointer by setting its contents to zero or NULL.
This has been the trend with most C/C++ runtimes so far, but it may change given that now we are at the threshold of 64 bit computing and embedded computing on more powerful devices.