指针类型默认决定取地址的区块,但是不想默认,地址前加(数据类型*)
n级指针,存的是(n-1)级指针的地址,可以间接修改(n-1)级指针的值
实际3级指针到顶
参数是指针的函数,一般是修改/使用外部变量(的地址?没听清)的值
01 一级指针——传参(有点指进来又指出去的意思)
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
//1
//int *p=&a;
void changeValue(int *p) {
*p = 2;
}
void test1()
{
int a = 1;
changeValue(&a);
printf("%d\n", a);
}
void main() {
test1();
system("pause");
}
02 二级指针——传参
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
//2 二级指针函数改地址
void changePointer(int** pp)
{
*pp = 0x008;
}
void test2() {
//int a=1;
//int* p = a; *p=a; p=&a;
//int** pp = &p; *pp=p; pp=&p;
int a = 1;
int* p = a;
changePointer(&p);
printf("%p\n", p);
}
void main() {
test2();
system("pause");
}