next up previous contents
Next: 傳送指標到函式 Up: 指標(pointers) Previous: 指標陣列   Contents

指標指向指標

  1. 宣告
    int **var;
    

    \begin{tikzpicture}[node distance=8em]\setlength \baselineskip{1ex}
\node [block,text width=4em] (adr0) {Address};
\node [block,text width=4em,right of=adr0] (adr1) {Address};
\node [block,text width=4em,right of=adr1] (value) {Value};
\node [above of=adr0,node distance=2em](ptr0) {Pointer};
\node [above of=adr1,node distance=2em](ptr1) {Pointer};
\node [above of=value,node distance=2em](var) {Variable};
\path [line] (adr0) -- (adr1);
\path [line] (adr1) -- (value);
\end{tikzpicture}

  2. 範例
    #include <stdio.h>
     
    int main ()
    {
       int  var;
       int  *ptr;
       int  **pptr;
    
       var = 3000;
    
       /* take the address of var */
       ptr = &var;
    
       /* take the address of ptr using address of operator & */
       pptr = &ptr;
    
       /* take the value using pptr */
       printf("Value of var = %d\n", var );
       printf("Value available at *ptr = %d\n", *ptr );
       printf("Value available at **pptr = %d\n", **pptr);
    
       return 0;
    }
    



2015-01-16