/*
字符数组的最后一个位置有一个空字符'\0',以表示存放的字符串的结尾
注意:
1.使用scanf函数的%s格式或gets函数输入字符串会自动添加'\0'
2.使用getchar(),需要手动添加'\0'到末尾,否则会输出乱码
*/
void demo2() {
	char str[25];
	for (int i = 0; i < 3; i++) {
		str[i]=getchar();
	}
	puts(str);
}

输出如下:

字符数组以'\0'结尾

相关文章: