Output of a C string program

前端 未结 3 501
说谎
说谎 2020-12-12 01:12
#include
int main()
{
  char s[2]=\"a\";
  s[1]=\'b\';s[2]=\'c\';s[3]=\'d\';s[5]=\'e\';
  printf(\"%s $%c$\",s,s[4]);
  return 0;
 }

3条回答
  •  孤城傲影
    2020-12-12 01:44

    You are writing/reading outside of the bounds of the array, this is simply undefined behavior you can not make any predictions about what the program will do.

提交回复
热议问题