|
-
Aug 6th, 2001, 08:50 AM
#1
Thread Starter
Junior Member
how do i declare and delete pointers??
-
Aug 6th, 2001, 09:22 AM
#2
Hyperactive Member
there..
If you want simple pointers, on the stack, you declare themlike 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;
now if you want a pointer on the heap space, you do it like this:
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;
I hope that helps...=)
Amon Ra
The Power of Learning.
-
Aug 6th, 2001, 09:25 AM
#3
Hyperactive Member
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..
Amon Ra
The Power of Learning.
-
Aug 6th, 2001, 09:40 AM
#4
PowerPoster
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;
-
Aug 6th, 2001, 10:01 AM
#5
Thread Starter
Junior Member
thnx allot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|