/********************************************************************** * * Copyright (c)2015,WK Studios * * Filename: A.h * * Compiler: GCC vc 6.0 * * Author:WK * * Time: 2015 6 7 * **********************************************************************/ #include<iostream> using namespace std; void main() { char a[100]={'0',48,48,0,0,'0'}; char b[]={'0',48,48,0,0,'0'}; char c[]={'0','0'}; char d[]={0}; //注意一下数字0与字符'0'区别 //'\0'等价于数字0而不是字符0 cout<<sizeof(a)<<endl; cout<<strlen(a)<<endl; cout<<sizeof(b)<<endl; cout<<strlen(b)<<endl; cout<<sizeof(c)<<endl; cout<<strlen(c)<<endl; cout<<sizeof(d)<<endl; cout<<strlen(d)<<endl;
运行结果:
100
3
6
3
2
7
1
0
版权声明:本文为博主原创文章,未经博主允许不得转载。
空闲时候思考2('\0'等价于数字0还是字符0)
时间: 2024-11-06 05:13:38