I came across these lines and did not make any sense to me.
int *XPos, *YPos;
int f;
int nFrames = 10;
XPos = new int [nFrames];
YPos = new int [nFrames];
the gist of other part of the code is XPos values and YPos values are calculated and stored in as XPos[f] and YPos[f]. If i use cout< XPos[0] << endl; I see 10 values of XPos in the first element of f. Is it possible for me to access the individual values in XPos? In other words, if i give XPos[0][0], will i be getting only the first number XPos instead of all the 10 values?
int *XPos, *YPos;
creates two pointers. Pointers point to addresses(as of now, nothing). int nFrames = 10;
nFrames is an int of value 10.
You can assign addresses to pointers. XPos = newint [nFrames];
Here, new keyword is used to allocate an unamed variable in the free memory. int [nFrames];
is like int a[nFrames];
except that it does not have a name.It does have an address(where it is located in memory)! And the "new int [nFrames]" returns that address and that address is assigned to XPos.
With YPos, another int[nFrames] is allocated in free memory and its starting address is given to YPos.
You can read up on Pointers on every c++ basics book. I recommend "Programming : Principles and practices using c++".
Hope I helped.