字符数组以''结尾

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

输出如下:

原文地址:https://www.cnblogs.com/ericling/p/14282074.html