[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>前言
本人是一个刚刚上路的IT新兵,菜鸟!分享一点自己的见解,如果有错误的地方欢迎各位大佬莅临指导,如果这篇文章可以帮助到你,劳请大家点赞转发支持一下!
<>一、'\0’是什么?
‘\0’ 是转义字符
,为了告诉编译器’\0’是空字符,而不是字符0.也就是结束标志,’\0’是字符串中的结束标志,如果没有’\0’这个结束标志,那么在输出的时候就有可能会出现乱码问题;
字符’0’对应的二进制为00110000,而’\0’对应的二进制为00000000;
<>二、'\0’的作用:
将字符串存储进字符数组时,有两种方式(将字符abc存储进字符数组);
char arr1[] = "abc";
这是第一种存储方式,暂且称它为老大;
char arr2[]={'a','b','c'};
这是第二种存储方式,称之为老二;
老大和老二都是将三个字符abc储存进字符数组;
但是他们会被区别对待;
咱们来看这段代码的运行结果:
结果表明:老大没问题,非常健康;老二就出现了乱码的情况;这是因为他们被区别对待了;虽然他们都是将字符"abc"存储进字符数组;但是老大在存储的时候,编译器会自动给把’\0’存储进去,不需要老大自己动手,编译器就帮他存了,\而老二就是你不存就乱码,存了就正常;
出现乱码情况是因为,在输出字符串时,找不到’\0’这个结束标志,就会找到什么就输出什么,直到找到’\0’;
但是这种情况也仅仅会出现在没有设置字符数组长度的时候,一但你设置了字符数组的长度,那么编译器就会把老大老二一视同仁了;
<>三、'\0’的一些自身属性
'\0’大小是多少,长度是多少呢?
咱们用arr1数组来测试
每个字符占一个字节,而arr1一共是四个字节的大小,说明’\0’的大小是一个字节;
而在计算长度的时候不会把’\0’算上,
既然’\0’也占一个字节,如果我不给他留这一个字节的空间,老大的存储方式还能正常运行吗
不给’\0’留一个字节的位置,编译器都没办法把’\0’给你存进去,也会出现乱码情况;
以上就是今天要分享的一些关于’\0’的见解了,如果各位朋友有不同的见解,欢迎在评论区讨论,指正;
谢谢!!!
写在最后:有人要卷死我,我必反卷之! ! !