I am a Java guy trying to learn C++.
I came across some code where following the type name, there is a *. For example:
char* socialNum[125][9];
and
CSampleDoc* pDoc = GetDocument();
What does the star mean?
I am a Java guy trying to learn C++.
I came across some code where following the type name, there is a *. For example:
char* socialNum[125][9];
and
CSampleDoc* pDoc = GetDocument();
What does the star mean?
That means that the variable is a pointer.
int myInt = 4;
int *myPointer = &myInt;
Now, myPointer
points to the integer myInt
. Pointing to something is basically holding the memory address of that something.
Since you said you come from Java, this in Java:
MyClass obj = new MyClass(); // obj is a reference (or pointer)
would be equivalent with this in C++:
MyClass *obj = new MyClass(); // obj is here a pointer as well.
// and once you are done with obj, don't forget to free the memory:
delete obj;
*
means it is a pointer
to a piece of data.
Take, for example, these:
int *myInt;
char *myChar;
MyClass *objectOfClass;
All of these are pointers to the data in memory. The value of the pointer is an int
, which is the address (location) in memory of that data.