so whenever you declare array with some name,
say char are;
you program will be allocated with 4 bytes of contiguous memory, and your array name itself acts as a pointer, but by default it's constant character pointer which means you can't reassign it.
string("hello llo") you are dealing with is string literal, it will be stored in some memory Location, just like an array it will terminated by null character,
char* h = "ghjh";
h has value j just like an array;
so here "hello llo" will return a pointer to this base memory where string is stored [g][h][j][h]['\0'], and it isn't stored in the array are.
so you're try to reassign to a constant character pointer,with some new memory Location which you are not allowed, you should read error message
i believe this is first time i see someone using puts() for string literal, that is nice!
Also, you maybe know this but the reader may not know. String pointed to is read-only string and cannot be modified like char can.
i always type const char *s for read-only strings so its more obvious that it cannot be changed. Then you also get a compiler warning if you do.
ch="hello llo"; //syntax error
The above code will show syntax error as size of array must be define while declaring a string
It is correct for pointers because the string inside quotes is allocated from the compiler at compile time, so you can point to this memory address.
s = "hello llo";
Here, your ch is of array type, and you are trying to use assignment in c with character array. In c, you can do this type of assignment at the declaration of array. Change this code to this and it will work...
char ch="hello llo";
hey bro i think array contain contigious memory but when we create a memory
we create a block and array name is like a pointer
as we see
int ch; ch='h';
here we see ch store a char h but question is what does mean of writing a name of array is like a base address of array then we write ch is like a pointer it treat likely pointer but it is not a pointer as we see an example
p="hello"; is valid
ch="hello" is not valid because it is not pointer and it is not auto increment
i hope u understand what eror is
you are right that it is the base address to a block of memory.
ch will fit all characters in "hello" but leaves out null-byte at the end , it would make it a char array but an invalid string. I also think *p and ch should be of type char (maybe it's a typo), but I get your point.