C: differences between char pointer and array [dup

2018-12-31 03:48发布

Consider:

char amessage[] = "now is the time";
char *pmessage = "now is the time";

I read from The C Programming Language, 2nd Edition that the above two statements don't do the same thing.

I always thought that an array is an convenient way to manipulate pointers to store some data, but this is clearly not the case... What are the "non-trivial" differences between arrays and pointers in C?

14条回答
临风纵饮
2楼-- · 2018-12-31 04:09

An array is a const pointer. You cannot update its value and make it point anywhere else. While for a pointer you can do.

查看更多
倾城一夜雪
3楼-- · 2018-12-31 04:12

The above answers must have answered your question. But I would like to suggest you to read the paragraph "Embryonic C" in The Development of C Language authored by Sir Dennis Ritchie.

查看更多
登录 后发表回答