linux C :char* ,char[], string类型

2023-05-16

1,char*:  表示指向字符串的指针,如char* str="hello";

2,char[ ]: 表示字符数组,如char  str[ ]="world";

3,string: 字符串类型,在C++中是定义成一个数据类型,和int 、char一样,如string str="helloworld";但是在C语言中没有string类型变量。

       #include<string.h>里声明的函数原型也全是针对char数组的种种操作,没有对string数据类型声明。

4,char* 和char[ ]可以相互转换,如:char str1[ ]="hehe";char* str2=str1; 

5,总结:a,C语言中字符串的表示就两种a   char*,  b  char[ ]; string类型在C语言中是不存在的

                   b,in Linux C,we should set the end 0f char array(end tag is data 0),eg ,arr[end]=0; when using printf ("output array =: %s",arr),screen just show the string stored in array.the rest of array will not show. if not do so,screen will show all the data in array.becase the rest of array are not assigned values,they are messy codes.

                   c,in C++,we needn't  set the end of char array,system will do it.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

linux C :char* ,char[], string类型 的相关文章

随机推荐