Skip to content

Instantly share code, notes, and snippets.

@re-imagined
Last active April 5, 2016 05:06
Show Gist options
  • Select an option

  • Save re-imagined/ceada6a24cf6d5c6a1e4 to your computer and use it in GitHub Desktop.

Select an option

Save re-imagined/ceada6a24cf6d5c6a1e4 to your computer and use it in GitHub Desktop.
用char 来声明字符串时,最后会接一个结束符,长度比字符数大一
char STR[] = "Hello\!";

有六个字符,但

cout << sizeof(STR); 

的结果是7,因为后面还有一个结束符 "\0"。

for(int i = 0 ; i<=6; i++){
cout<<STR[i];  }

一样可以输出 Hello!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment