指向指针的指针变量有什么用

    技术2022-05-19  20


    最佳答案

     

    我给楼主一个最直接的理由:那就是如果你希望在一个函数的参数中改变一个指针的值,你就只能传这个指针的指针给这个函数。 比如有int *p; 而你想在函数f中对其增量,就只好: void f(int **pp) {   *pp++; } #include<iostream.h>main(){    //声明指针数组    char *colors[]={"Red","Blue","Yellow","Green"};     //指向指针的指针变量    char **pt;                 //通过指向指针的变量访问其指向的内容    pt=colors;    for (int i=0;i<=3;i++) {        cout<<"pt="<<pt<<endl;        cout<<"*pt="<<*pt<<endl;        cout<<"**pt="<<**pt<<endl;        pt++;    }}

    最新回复(0)