Confusion about pointers and their memory addresses
Posted
by TimothyTech
on Stack Overflow
See other posts from Stack Overflow
or by TimothyTech
Published on 2010-06-11T16:59:41Z
Indexed on
2010/06/11
17:02 UTC
Read the original article
Hit count: 166
alright, im looking at a code here and the idea is difficult to understand.
#include <iostream>
using namespace std;
class Point
{
public :
int X,Y;
Point() : X(0), Y(0) {}
};
void MoveUp (Point * p)
{
p -> Y += 5;
}
int main()
{
Point point
MoveUp(&point)
cout <<point.X << point.Y;
return 0;
}
Alright, so i believe that a class is created and X and Y are declared and they are put inside a constructor
a method is created and the argument is Point * p, which means that we are going to stick the constructor's pointer inside the function;
now we create an object called point then call our method and put the pointers address inside it?
isnt the pointers address just a memory number like 0x255255?
and why wasnt p ever declared?
(int * p = Y)
what is a memory addres exactly? that it can be used as an argument?
© Stack Overflow or respective owner