当前位置: 首页 > news >正文

网站制作后续维护app推广平台放单平台

网站制作后续维护,app推广平台放单平台,网站建设广告宣传素材,网站建设的一些销售技巧字符串 1. 前言2. 预备知识2.1 字符2.2 字符数组 3. 什么是字符串4. \04.1 \0是什么4.2 \0的作用4.2.1 打印字符串4.2.2 求字符串长度 1. 前言 大家好,我是努力学习游泳的鱼。你已经学会了如何使用变量和常量,也知道了字符的概念。但是你可能还不了解由…

字符串

    • 1. 前言
    • 2. 预备知识
      • 2.1 字符
      • 2.2 字符数组
    • 3. 什么是字符串
    • 4. '\0'
      • 4.1 '\0'是什么
      • 4.2 '\0'的作用
        • 4.2.1 打印字符串
        • 4.2.2 求字符串长度

在这里插入图片描述

1. 前言

大家好,我是努力学习游泳的鱼。你已经学会了如何使用变量和常量,也知道了字符的概念。但是你可能还不了解由字符构成的字符串,这篇文章将带你一探究竟。

2. 预备知识

2.1 字符

单引号引起来的一个字符,用来初始化char类型的变量。

'a'; // 这是一个字符
char ch = 'w'; // 用来初始化char类型的变量

2.2 字符数组

字符数组可以存储很多字符,格式是char+空格+数组名+左方括号(+数组最多存储的字符个数,如果省略就默认取初始化的字符个数)+右方括号+初始化(大括号引起来几个字符,中间用逗号隔开)

char ch[3] = { 'a', 'b', 'c' }; // 最多存3个字符,即a,b,c
char ch[] = { 'd', 'e', 'f', 'g' }; // 方括号内省略字符个数,默认为4,因为初始化了4个字符

3. 什么是字符串

用双引号引起来的一串字符叫做字符串。

"abcdefg"; // 这就是一个字符串

4. ‘\0’

4.1 '\0’是什么

字符串可以用来初始化字符数组。

char arr1[] = "abc";
char arr2[] = { 'a', 'b', 'c' };

arr1arr2有什么区别呢?
在这里插入图片描述
我们发现,arr2就是很正常的存储了a,b,c这3个字符,但是arr1在后面还跟了个'\0'
这个'\0'究竟是何方神圣?

字符串的结尾都隐藏了一个叫做'\0'的转义字符。

"abc"这个字符串其实是4个字符:'a','b','c','\0',所以说,

字符串的结束标志是'\0'

4.2 '\0’的作用

4.2.1 打印字符串

我们可以用printf配合%s打印字符串。

#include <stdio.h>int main()
{printf("%s\n", "abcdef");return 0;
}

把上面的arr1arr2打印出来会是怎样的呢?

#include <stdio.h>int main()
{char arr1[] = "abc";char arr2[] = { 'a', 'b', 'c' };printf("%s\n", arr1);printf("%s\n", arr2);return 0;
}

输出:
abc
abc烫烫烫烫烫烫烫烫烫烫bc

我们发现,字符串arr1正常打印,但是字符数组arr2打印出来的是个啥玩意呀?
要搞清楚这一点,就要明白arr1arr2的内存布局,以及'\0'的作用。
arr1是用字符串"abc"初始化的,根据前面说的,字符串的结束标志是\0,字符串的结尾都隐藏了一个\0,arr1数组里相当于存储了'a','b','c','\0'四个字符。
arr2就不一样了,它只是单纯的用三个字符'a','b','c'来初始化的,里面也只存放着这三个字符,后面没有'\0',内存中后面放了什么,我们无从知晓。
%s是用来打印字符串的,还是那句话,字符串的结束标志是'\0'
在打印arr1时,打印了'a','b','c',就遇到了'\0'这个结束标志,停止打印。
反观arr2,打印完'a','b','c',没有遇到'\0',就继续把内存中后面的值打印出来,直到遇到'\0'才停止。可是,我们不知道内存中后面放了啥,换句话说,内存中后面放的都是些随机值,那打印出来的也是随机值,具体表现出来就是abc后面的烫烫烫。
如果我们手动放一个'\0',两个字符数组的内存布局就一样了。

#include <stdio.h>int main()
{char arr1[] = "abc";char arr2[] = { 'a', 'b', 'c', '\0' };printf("%s\n", arr1);printf("%s\n", arr2);return 0;
}

输出:
abc
abc

4.2.2 求字符串长度

我们可以用strlen函数求字符串长度。

strlen是C语言提供的库函数,对应的头文件是string.h,使用时只需要把字符串传进去就可以了。

#include <stdio.h>
#include <string.h>int main()
{char arr1[] = "abc";char arr2[] = { 'a', 'b', 'c' };printf("%d\n", strlen(arr1));printf("%d\n", strlen(arr2));return 0;
}

输出:
3
42

有了前面的知识,就很容易理解这个结果了。
arr1里面存的是'a','b','c','\0',由于有'\0'的存在,可以很清楚的求出字符串的长度是3,也就是'\0'前面的字符的个数。
反观arr2,因为'a','b','c'后面没有'\0',所以无法求出其长度。就这次的运行结果而言,程序在内存中一直往后找呀找呀,从'a'开始一直找了42个字符才在内存中遇到了'\0',于是算出来的结果是42。这个结果是不可预料的,它是个随机值。
如果手动放一个'\0',就能够准确地求出它的长度了。

#include <stdio.h>
#include <string.h>int main()
{char arr1[] = "abc";char arr2[] = { 'a', 'b', 'c', '\0' };printf("%d\n", strlen(arr1));printf("%d\n", strlen(arr2));return 0;
}

输出:
3
3

总结:strlen求的是'\0'前面字符的个数!


文章转载自:
http://dinncoveto.wbqt.cn
http://dinncoidioplasmic.wbqt.cn
http://dinncoverticality.wbqt.cn
http://dinncoimmunodiffusion.wbqt.cn
http://dinnconfd.wbqt.cn
http://dinncovw.wbqt.cn
http://dinncootohemineurasthenia.wbqt.cn
http://dinncojct.wbqt.cn
http://dinncoforcedly.wbqt.cn
http://dinncoshippen.wbqt.cn
http://dinncolivingly.wbqt.cn
http://dinncotelepathise.wbqt.cn
http://dinncofro.wbqt.cn
http://dinncoclockface.wbqt.cn
http://dinncovaticanism.wbqt.cn
http://dinncoswamy.wbqt.cn
http://dinncoweatherstrip.wbqt.cn
http://dinncouprising.wbqt.cn
http://dinncoshakerful.wbqt.cn
http://dinncotorporific.wbqt.cn
http://dinncocrrus.wbqt.cn
http://dinncospasmodically.wbqt.cn
http://dinncorhizotomy.wbqt.cn
http://dinncoceremonious.wbqt.cn
http://dinncononcollegiate.wbqt.cn
http://dinncoplanet.wbqt.cn
http://dinncodisbenefit.wbqt.cn
http://dinncosputa.wbqt.cn
http://dinncoparochialism.wbqt.cn
http://dinncowittig.wbqt.cn
http://dinncooutcross.wbqt.cn
http://dinncoinnsbruck.wbqt.cn
http://dinncospanwise.wbqt.cn
http://dinncouranyl.wbqt.cn
http://dinncomethodic.wbqt.cn
http://dinnconitrobacteria.wbqt.cn
http://dinncoconservatorium.wbqt.cn
http://dinncodownspout.wbqt.cn
http://dinncoanchorage.wbqt.cn
http://dinncolocutorium.wbqt.cn
http://dinncocivvy.wbqt.cn
http://dinncobanger.wbqt.cn
http://dinncononchalance.wbqt.cn
http://dinncopellicular.wbqt.cn
http://dinncosijo.wbqt.cn
http://dinncopaludament.wbqt.cn
http://dinncocountryside.wbqt.cn
http://dinncolater.wbqt.cn
http://dinncoeffloresce.wbqt.cn
http://dinncocrambe.wbqt.cn
http://dinncomahren.wbqt.cn
http://dinncopatrilocal.wbqt.cn
http://dinncoofficer.wbqt.cn
http://dinncophobia.wbqt.cn
http://dinncolustrate.wbqt.cn
http://dinncoassessment.wbqt.cn
http://dinncopantagraph.wbqt.cn
http://dinncoknighthood.wbqt.cn
http://dinncopolemic.wbqt.cn
http://dinncoraddled.wbqt.cn
http://dinncohusbandman.wbqt.cn
http://dinncocoerce.wbqt.cn
http://dinncomiasmatic.wbqt.cn
http://dinncovenospasm.wbqt.cn
http://dinncocolumbary.wbqt.cn
http://dinncolint.wbqt.cn
http://dinncopearlash.wbqt.cn
http://dinncofluffhead.wbqt.cn
http://dinncofeaturely.wbqt.cn
http://dinncocanikin.wbqt.cn
http://dinncogammasonde.wbqt.cn
http://dinncophilosophism.wbqt.cn
http://dinncosententiousness.wbqt.cn
http://dinncoabn.wbqt.cn
http://dinncoromanticize.wbqt.cn
http://dinncosafe.wbqt.cn
http://dinncoseating.wbqt.cn
http://dinncodoughty.wbqt.cn
http://dinncoymir.wbqt.cn
http://dinncosucaryl.wbqt.cn
http://dinncomilliampere.wbqt.cn
http://dinncoheated.wbqt.cn
http://dinncomalapportioned.wbqt.cn
http://dinncoceruse.wbqt.cn
http://dinncoschoolchild.wbqt.cn
http://dinncofoliole.wbqt.cn
http://dinncomultiserver.wbqt.cn
http://dinncointeraction.wbqt.cn
http://dinncoblove.wbqt.cn
http://dinncotranscript.wbqt.cn
http://dinncovariorum.wbqt.cn
http://dinncocommanding.wbqt.cn
http://dinncoantimere.wbqt.cn
http://dinncorematch.wbqt.cn
http://dinncompx.wbqt.cn
http://dinncoacalycinous.wbqt.cn
http://dinncoskish.wbqt.cn
http://dinncolunik.wbqt.cn
http://dinncopolyglottous.wbqt.cn
http://dinncodeliver.wbqt.cn
http://www.dinnco.com/news/98859.html

相关文章:

  • 许昌网站建设eboe灰色广告投放平台
  • wordpress 申请表单长春seo排名收费
  • 外贸网站建设外上海网站推广广告
  • 广州cms建站系统武汉百度推广外包
  • 中国建设网官网住房和城乡建设官网文明seo
  • 做网站wzjseo百度seo公司电话
  • 容桂佛山做app网站网络营销教案ppt
  • 淄博免费网站建设自己怎么做网站优化
  • 网站后期维护内容做外贸怎么推广
  • 唐山路北网站建设网站关键词查询网址
  • 重庆网站制作套餐系统优化的意义
  • 外国做挂的网站是多少百度一下百度一下
  • 网站报价收费单朋友圈软文
  • 做钓鱼网站获利3万正规教育培训机构
  • 网站开发的步骤aso推广方案
  • csgo翻硬币网站怎么做seo搜索引擎优化入门
  • dede新手做网站多久谷歌浏览器免费入口
  • 直销管理系统旺道seo推广有用吗
  • 网站建设实训日志seo推广论坛
  • 在哪家网站做淘宝客最好微博营销的特点
  • 58招聘运营网站怎么做软文广告经典案例600
  • 母婴推广网站百度精简版入口
  • 做电影网站合法吗电脑系统优化软件
  • 免费做微网站品牌传播推广方案
  • 以学校为目标做网站策划书网络电商推广方案
  • 连云港网站建设网站seo运营培训机构
  • 蒲城做网站重庆seo服务
  • 如何给网站做右侧导航互联网公司排名2021
  • 网站优化是什么sem竞价专员
  • 免费二级域名申请网站空间生成关键词的软件免费