Given that all the primitive data types and objects have memory allocated, it is intuitively easy to imagine the pointers to these types.
But where exactly do function pointers point to? Given that instructions are converted into machine code and reside in memory, should we consider they point to the memory location corresponding to the start of the functions instructions?
We face many errors in pointers due to illegal memory access. Is it the case that errors occur when function pointers point to data memory instead of instruction memory?
Function pointer also point into memory, the only difference is that there is executable code at that memory location instead of data.
On many platforms if you try to execute data (e.g. regular memory) you’ll crash or cause an exception. This is known as Data Execution Prevention – a security measure to prevent applications inadvertently running dodgy code that may be placed there by malware.