指针的基本知识点

#include<stdio.h>

void A(int *c)
{//c存的是cntptr存储的地址 
    int b=4;
    c = &b;//改变的只是c的指向,主函数的值不受影响 
}
void B(int *c)
{//c存的是cntptr存储的地址 ,指向cntptr指向的地址 
    int b=8;
    *c = b;//改变指向地址存的值 
}
int main()
{
    int count = 5,*cntptr = NULL;
    cntptr = &count;
    printf("调用函数前
");
    printf("count的地址%p
",&count);//实际地址取决于所用的机器,编译器,操作系统 
    printf("cntptr的值%p
",cntptr);
    A(cntptr);//该函数改变的只是形参的指向 
    printf("调用函数后
");
    printf("count的地址%p
",&count);//实际地址取决于所用的机器,编译器,操作系统 
    printf("cntptr的值%p
",cntptr);

    printf("调用函数前
");
    printf("count的值:%d
",count);
    printf("*cntptr的值:%d
",*cntptr);
    B(cntptr);//该函数改变的是形参指向的地址所储存的值 
    printf("调用函数后
");
    printf("count的值:%d
",count);
    printf("*cntptr的值:%d
",*cntptr);
    *cntptr = 10;
    printf("count的值:%d
",count);
    printf("*cntptr的值:%d
",*cntptr);
    return 0;
}

指针自己没学好 所以现在一边学数据结构一边复习指针

原文地址:https://www.cnblogs.com/hellocheng/p/7350146.html