结构体指针

参考http://www.cplusplus.com/doc/tutorial/structures/

#include <stdio.h>

struct People{
    int age;
    
};

int main(int argc, const char * argv[])
{

    struct People *p = malloc(sizeof(struct People));
    p->age = 10;

    struct People *p1 = p;
    p->age = 12;//p1的值也会改变,如果不是指针类型则不会有影响

    printf("age:%d\n", p1->age);

    free(p);//释放内存
    system("pause");
    return 0;
}

 

posted @ 2016-03-15 23:50  haxnt  阅读(177)  评论(0编辑  收藏  举报