I am trying to understand pointers in C but I am currently confused with the following:
char *p = \"hello\"
This is a char pointer
char p[3] = "hello"
? should be char p[6] = "hello"
remember there is a '\0' char in the end of a "string" in C.
anyway, array in C is just a pointer to the first object of an adjust objects in the memory. the only different s are in semantics. while you can change the value of a pointer to point to a different location in the memory an array, after created, will always point to the same location.
also when using array the "new" and "delete" is automatically done for you.
You're not allowed to change the contents of a string constant, which is what the first p
points to. The second p
is an array initialized with a string constant, and you can change its contents.