double ptr Usage #2 – special reseating #c#

Double pointer has many usages in c++. Usage #1 is array of pointers. Here’s Usage #2

Q: in a function, can you reseat a pointer object (32bit) created outside the function?
A: possible in C. pointer-to-pointer is a C-specific construct that can reseat the “nested” pointer.

int var3 = 3, var9 = 9;
void reseat(int ** ptr){ *ptr =  &var9; }
int main(){
    int * intp = &var3;
    reseat(&intp); //intp is a pointer-to-int, now reseated to &var9

C# has a similar feature in “ref” params.

In java, a reference param to a method is always a local ptr Variable pointing to the argument Object. Once you reseat this local ptr Variable, you lose the argument object. You can’t reseat the original ptr Variable declared outside your method.

void metho1(Object param){
  param=new Object(); // reseating

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s