char four[4] = “four”; What are the correct semantics for this statement?

后端 未结 4 2028
逝去的感伤
逝去的感伤 2021-01-18 07:23
int main(void)
{
    char four[4] = \"four\";
    return 0;
}

When compiled as a C++ program, G++ reports

xxx.cpp: In function int

4条回答
  •  庸人自扰
    2021-01-18 07:50

    The string "four" actually contains five bytes: the four letters plus a zero byte (\0) as a string terminator. It's been a while since I've written C or C++, but I would guess the C compiler is silently ignoring it for whatever reason.

提交回复
热议问题