The case with pointers This works because when you assign as str1="Hello" , you actually create a string literal called hello, allocating it somewhere in memory and assigning the first character of the literal to the pointer to the pointer, and since the pointer is not constant, you can assign it again with different addresses. Another important point is that the string literal is created in read-only memory.
The case with a character array You can assign a string literal to it, while initialization will be supported by the language. And do not confuse the assignment with initialization. While the destination, since its array of characters, you must change the character of the value by character, you are trying to address the first address of the string literal to the first character of the array (the name of the array returns the address of the first element of the array). And this is clearly wrong, since the first element is not a pointer, it cannot store the address.
joker007 Feb 27 '17 at 5:22 2017-02-27 05:22
source share