/**********************************************************************      
* *   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
不行的话再看一个:
#include <iostream>
using namespace std;
void example()
{
	int i;
	char acNew[20];
	for(i = 0; i < 5; i++)
	{
		acNew[i] = ‘0‘ ;
	}
	printf("%d\n",strlen(acNew));
	return ;
}
void main()
{
	example();	
}结果是一个随机的值,由于strlen没有找到结束的表示符‘\0’
略微修改一下:
#include <iostream>
using namespace std;
void example()
{
	int i;
	char acNew[20];
	for(i = 0; i < 5; i++)
	{
		acNew[i] = 0 ; // ‘\1‘  0
	}
	printf("%d\n",strlen(acNew));
	return ;
}
void main()
{
	example();	
}
空暇时候思考2('\0'等价于数字0还是字符0)
原文:http://www.cnblogs.com/zhchoutai/p/6853740.html