2009年1月13日

多重指標 用法

// 範例 1
#include  
using namespace std; 

int main() {
    int x = 123; 
    int *x1 = &x; 
    int **x2 = &x1; 
    int ***x3 = &x2;
    
    cout << "x = " << x << endl << endl; 

    cout << "*x1 = " << *x1 << endl; 
    cout << "x1 = " << x1 << endl << endl; 
    
    cout << "**x2 = " << **x2 << endl; 
    cout << "*x2 = " << *x2 << endl; 
    cout << "x2 = " << x2 << endl<< endl;
    
    cout << "***x3 = " << ***x3 << endl; 
    cout << "**x3 = " << **x3 << endl; 
    cout << "*x3 = " << *x3 << endl; 
    cout << "x3 = " << x3 << endl<< endl; 
}
//範例 2
#include  
using namespace std;  

void f( char **fc ){
     *fc=" ";    
}

int main(){
    
    char *c = "123";
    
    f(&c);
    
    cout << c; 
}

沒有留言: