Loose-Info.com
Last Update 2012/07/05
TOP - C言語 - 文字列のサイズ

文字列は終端に'\0'が配置されたcharの配列です。
従って実際の配列のサイズは、引用符を用いて指定した文字列より1文字分多くなります。

(例)
#include <stdio.h> #include <string.h> int main () { char s[] = "0"; printf("文字数 : %d\n", (int)strlen(s)); printf("配列サイズ : %d\n", (int)sizeof(s)); if (s[1] == '\0') { printf("s[1]は'\\0'\n"); } return 0; }

実行結果
文字数 : 1 配列サイズ : 2 s[1]は'\0'