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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值