string literal in c

前端 未结 6 947
刺人心
刺人心 2021-01-05 09:12

Why is the following code illegal?

typedef struct{
   char a[6];
} point;

int main()
{
   point p;
   p.a = \"onetwo\";
}

Does it have any

6条回答
  •  孤城傲影
    2021-01-05 10:06

    Note that in order to store the string "onetwo" in your array, it has to be of length [7] and not as written in the question. The extra character is for storing the '\0' terminator.

提交回复
热议问题