First of all, I want to apologise for posting this in Random, but I wouldn’t know where else it would fit.
As the title implies, I’ve got a question about C++. I’m currently at the point of learning pointers and memory addresses. I understand how it works, because I have a programming background in Think Pascal on Mac, and that language has the same things.
My question is what this means:
double dVar = 10.0;
piVar = (int)pdVar;
The first line creates a pointer called piVar, that points to an integer.
The second line creates a variable of the type double called dVar.
But I’m unsure what the third line does.
This code is supposed to be an example of how to convert pointers from pointing to one type of variable to another, but I don’t understand what the third line does.
The & operator points to an address in the memory:
// create an integer called myvar;
// create an integer pointer called pMyVar
pMyVar = &myvar;
// link pMyVar to the memory address of myvar
I know that it is used in this way, but I don’t know what this would mean:
Because of this, I’m also unsure what the fourth line does, because I figured it might be a typo that had to have been this:
That would make sense, because it defines pdVar as a pointer to a variable of the type double.
Can anyone clear my view upon this ?