?:confused: :confused: :confused:
Printable View
?:confused: :confused: :confused:
If you want simple pointers, on the stack, you declare themlike this:
now if you want a pointer on the heap space, you do it like this:Code:int a; //an integer
int *pInt; //a pointer to an integer...
//you could have initialized it on the previous line, but you can also do it like this
pInt = &a;
I hope that helps...=)Code:int *pInt = new int; //that creates a pointer to an integer on the heap. Initialize it like above
int a;
pInt = &a; //now pInt points to a;
ok, i forgot to say how to delete a pointer on heap
Code:int a;
int *pInt = new int;
pInt = &a;
//now to free the memory
delete pInt;//deletes the pointer on the heap..
If you talk about create/delete a pointer point to a string then..
:)PHP Code://Create a pointer point to a string with size of 10
char *MyStr = new char[10];
//Reset the content
memset(MyStr, 0, 10);
//. Put your code here...
//Delete the pointer
delete [] MyStr;
:D :cool: :p