Pointer Arithmetic is a good point where to start.
I'm going to try to explain you briefly how it works, but I strongly suggest you to integrate those concepts with a good book or internet references because they are very important for proper handling pointers.
A pointer (as you can imagine from the name) points a memory cell:
int* ptr = /*an address to the memory cell*/
Your memory is composed by sequentially cells, graphically:
Address| Value
-------|------------
0x00 | [#some value] 8 bit
0x01 | [#some value] 8 bit
... | ...
0xN | [#some value] 8 bit
Just to make this example not so long, we can assume each cell contains 8 bits and a integer value is represented with exactly 32 bit (usually that is not true, and it depends on the machine architecture and compiler).
Then a int value is stored exactly in 4 cells. (We explicitly don't consider memory alignment).
So your pointer contains a memory location, the address in the memory which contains the value you've allocated (with the usage of dynamic memory).
For example:
int* ptr = 0x01
That means the variable ptr, stored somewhere in the memory, contains the address 0x01. In the memory cell 0x01 there will be the integer value allocated dynamically.
But, since the value is an integer type, the data will take 4 cell in order to store the complete information. So the data will be "split" among the cell 0x01, 0x02, 0x03, 0x04.
The pointer will points the first memory location of the data, and the number of cell occupied is given by the type of pointer (in that case pointer int so the compiler knows the information starts from cell 0x01 and ends 0x04).
A variable pointer can be evaluated in an arithmetic expression, such sums and differences.
Fo example:
ptr + 10
ptr - 10
Simply, the meaning of that expression is to access to memory address starting from the address stored in ptr and jumping 10 int cells forward or backward.
Attention Note: the expression does not mean to simply add the value to the address obtaining a new address.
Indeed, assuming ptr = 0x01, then the expression:
ptr + 10;
does not mean 0x01 + 10 = 0xa!
Instead that means to jump 10 "block" of size equal to the type's size
pointed by the pointer itself.
That is, 0x01 + 10 * 4bytes.
Since ptr is a pointer to int, then +10 means "plus 10 block of integers", and, in this example, each int occupies 4 bytes (32 bit).
To conclude, the expression:
*(pointer + counter) = temp;
means to access to the address start from pointer and adding #counter block of int, then deference that address with the operator* and write in that address the value temp.
That notation can be easily simplify with the operator[]:
pointer[counter] = temp;
where the meaning is exactly the same, but the notation is more readable, especially when you have to do with array.
*(pointer + counter)is just another (and wackier) way to writepointer[counter]. It's not clear why the author chose to obfuscate matters in this way. In any case, it would have been better to usestd::vector<int>in place of raw pointers and manual memory management.std::vector.pointeruntil it's used, i.e.,int *pointer = new int[input];; and definetempinside the body of theforloop, since that's the only place it's used.