> For the complete documentation index, see [llms.txt](https://easonwang.gitbook.io/c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easonwang.gitbook.io/c/xing-bie/zi-chuan.md).

# 字串

```c
char s[] = "Hello World";
char *s  = "Hello World";
```

* char s\[] 是個char array，含12個byte(包含結尾\0)
* char \*s 是一個 pointer 指向 char，s 指向 "Hello World" 這個string literal的起始記憶體位置

## 範例：

```c
#include <iostream>
using namespace std;
 int main() {
  char s1[] = "Hello World";
  char *s2  = "Hello World";

  cout << "size of s1: " << sizeof(s1) << endl;
  cout << "size of s2: " << sizeof(s2) << endl;
}
```

> 結果為：
>
> size of s1: 12
>
> size of s2: 4

## 結論

char \*s速度較快
