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


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

您正在使用您的 账号评论。 登出 /  更改 )

Google photo

您正在使用您的 Google 账号评论。 登出 /  更改 )

Twitter picture

您正在使用您的 Twitter 账号评论。 登出 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 登出 /  更改 )

Connecting to %s