ALEXKK2011

The Technical Side of alexKK2011
  博客园  :: 新随笔  :: 订阅 订阅  :: 管理

pointer’s pointer

Posted on 2011-02-24 17:46  alexkk2011  阅读(170)  评论(0编辑  收藏  举报
#include <iostream>

using namespace std;

void GetMem(char** p, int n)
{
    *p = (char*)malloc(sizeof(char)*n);
};

void main()
{
    char c[] = "a";
    char* ptr = c;//NULL;
    GetMem(&ptr, 100);
    strcpy(ptr,"hello!");
    cout << ptr << endl;
    cout << *ptr << endl;
    cout << &ptr << endl;
}
see the procedure:
1.1 
 

2.2

3.3

4.4

5.5