char *str1;
str1 = "Hello";
In the above code, does str1 = "Hello";
indicate string copy? what are the reasons?
char *str1;
str1 = "Hello";
In the above code, does str1 = "Hello";
indicate string copy? what are the reasons?
Actually, C language itself is not fully aware of strings. It only handles characters and pointers to them. What makes a C string is a convention by which an array of characters (an array is just a pointer to an allocated blob of memory) terminated by a null character '\0'
can be handled as a string.
The only place where C is aware of strings is literal constants in code, like "Hello"
in your example, which allocate memory containing those characters and followed by '\0'
.
char *
does not declare a string variable. It declares a pointer to a character.