Initializer-string for char array is too long

2019-09-17 11:53发布

问题:

I have read char four[4] = "four"; What are the correct semantics for this statement?

I am using Xcode and writing Objective C code. I don't understand why:

char words[4] = { "aardvark", "abacus", "allude", "zygote" };

gives a warning

warning: Semantic Issue: Initializer-string for char array is too long

but

char *words[4] = { "aardvark", "abacus", "allude", "zygote" };

works fine. Kindly guide me.

回答1:

I was not aware of the differences between an integer pointer and a character pointer. Hence, I was confused. This helped me: http://www.computing.net/answers/programming/why-this-works-char-pointer-in-c/4444.html