一级指针,二级指针,指针和数组,指针数组,数组指针

首先先来对指针就行一个简单的回顾.
指针(指针是什么,指针和指针的类型)
在对指针有了一个简单的了解之后,接下来我们就来看看指针更深层次的内容.
在我们的一级指针中,其实它不光光能指向一个数字

int i = 10;
int* p = &i;

除此之外,还有字符指针,数组指针,函数指针等等.
首先我们来看字符指针,通过前面对指针的简单回顾,我们知道,在指针的类型中有一种指针类型为字符指针 char*.
字符指针的一般使用:

int main(){
	char ch = 'w';
	char* pc = &ch;
	*pc = 'w';
	system("pause");
	return 0;
}

看一段代码:

#include <stdio.h>
#include <stdlib.h>
int main(){
	char* pstr = "hello world";
	printf("%s\n", pstr);
	system("pause");
	return 0;
}

我们这样去做是不是就把字符串"hello world"放到pstr中去了呢?千万不要这么想!这里的本质是将字符串"hello world"的首地址放在了pstr中.
接下来看这样一道题目:

#include <stdio.h>
#include <stdlib.h>
int main(){
	char str1[] = "hello world";
	char str2[] = "hello world";
	char* str3 = "hello world";
	char* str4 = "hello world";
	if (str1 == str2){
		printf("str1 and str2 are same\n");
	}
	else {
		printf("str2 and str2 are not same\n");
	}
	if (str3 == str4){
		printf("str3 and str4 are same\n");
	}
	else {
		printf("str3 and str4 are not same\n");
	}
	system("pause");
	return 0;
}

结果如下:
在这里插入图片描述
这道题目也就验证我们之前所强调知识点.
str1 == str2 与 str3 == str4所判断的是首元素地址,str1与str2是分辨开辟出来的两块内存,首地址必然不相同,但str3与str4是两个指针,都保存了字符串"hello world"的首元素地址,都指向同一个字符创所以得到如上图所示的结果!
接下来回顾数组指针.
关于数组指针,指针数组,二级指针

对于数组指针和指针数组的理解及其应用

对函数指针的回顾

关于函数指针,函数指针数组以及函数指针数组的用法(计算器的实现)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值