編譯環境:vs2008(XP)
#include <iostream>
using namespace std;
int main()
{
cout<<'\\n'<<endl;
return 0;
}
代碼如上,結果是23662(5C6Eh);'\\n'中經過編譯器解析後內存實際的內容是'\n',因爲'\'的Assic碼是5Ch(十進制92),'n'是6Eh(十進制110)
#include <iostream>
using namespace std;
int main()
{
cout<<'abcd'<<endl;
return 0;
}
結果是1633837924(61626364h);'abcd'內存佈局是61626364,剛好是a、b、c、d的Assic值
#include <iostream>
using namespace std;
int main()
{
cout<<'abcde'<<endl;
return 0;
}
結果顯示錯誤:常量中的字符太多。結論:'abcd'會被編譯器解析爲61626364h,即依次在內存中排列a、b、c、d的assic碼;但是''中的內容加起來不能超過4字節。
拓展:
試一試下面的程序:
#include <iostream>
using namespace std;
int main()
{
cout<<'我是誰'<<endl;
return 0;
}