-------------------
int *numPtr; // declare a pointer to an integer.
numPtr = (int*)malloc(sizeof(int));
This code is a bit strange. For one the casting (int*) is unnecessary as the compiler will handle that for you. With that being said however, the code works as follows:
malloc accepts one argument, which is the number of bytes to allocate memory for (sizeof(int)).
In this case, you have only requested sizeof(int) bytes, or 4 most likely. Which means you have only enough memory to store 1 int.
Malloc then returns a pointer to newly allocated memory. so numPtr (nump) will now point to this new dynamically allocated memory. Keep in mind that mallocing memory does not place any value's in that spot. It only reserves the spot. If you dereference your pointer, you can then store an integer.
Now, malloc genreally would be used to create an array with the following code:
numPtr = malloc(sizeof(int) * 10) // This code will malloc space for 10 intengers. Which can be accessed by incrementing your pointer. The malloc here returns the address of the first spot. numPtr + 1 gives you the address of the second spot. (Exactly like array indexing).
Just like this:
numAry[10];
numAry[1] == *(numPtr + 1); //This statements are equal.