1.從字符串的長度:——>空字符的長度為0,空格符的長度為1。
2.雖然輸出到屏幕是一樣的,但是本質的ascii code 是不一樣的,他們還是有區別的。
#include<iostream>
using namespace std;
int main(){
char a[] = " ";
char b[] = "\0";
cout << strlen(a) << endl; // 1
cout << strlen(b) << endl; // 0
char arr[] = "a b";
char brr[] = "a\0b";
cout << arr << endl; // a b //長度為 3
cout << brr << endl; // a //長度為1 ,因為遇到'\0'代表結束
system("pause");
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char a, b;
a = '\0';
b = ' ';
//純輸出
cout << "a: " << a << endl << "b: " << b << endl;
//ascii number
cout << "a: " << (int)a << endl; // 0
cout<< "b: " << (int)b << endl; // 32
char str1[] = { 'a', ' ', 'b','\0' };
char str2[] = { 'a', 'b', '\0'};
cout << str1 << endl; //a b
cout << str2 << endl; //ab
system("pause");
return 0;
}