指针 指针数组(一维/二维)遍历

基本概念

指针变量是存放内存地址的变量,指针本质上也是内存地址,但是我更愿意象形地把它理解成为指向一块内存的pointer,一个简单的程序

void swap_i(int a1, int b1) {
                             //传参交换
	int temp;
	temp = a1;
	a1 = b1;
	b1 = temp;
	printf("a1 = %d\nb1 = %d\n", a1, b1);
	printf("a1Address = %d\na2Address = %d\n", &a1, &b1);
}
void swap_ptr(int* a,int* b) {
                          //指针交换
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;

	printf("*a = %d\n*b = %d\n", *a, *b);
	printf("a = %d\nb = %d\n", a, b);
}
int main()
{
   
	int c;
	int a = 9, b = 100;                          //分别利用指针和传参函数交换a和b的值
	int* p = NULL;
	printf("aAddress = %d\nbAddress = %d\n", &a, &b);
	printf("交换前  a = %d, b = %d\n", a, b);
	swap_ptr(&a, &b);                            //指针交换的传参一定是传给指针变量,所以要传a和b的地址
	c =

你可能感兴趣的:(c语言,算法,c++)