Please look at the following code snippets: char str[]="abcd"; // Gets stored in stack frame. char *str="abcd"; // Where does this gets stored? In case of first declaration ie char str[]="abcd"; the string "abcd" gets stored in the stack frame of the invoked funciton. I wonder where does the string gets stored when we declare char *str="abcd"; (Is it in the heap?). Please reply. Thanks Iqbal
It simply means that you cannot modify the string since it's stored in some non-modifiable momory whereas your other one can by modified.
You are not allowed to modify that. If you do that, results are unpredicatable i.e it may work or it may not work. You should not do that.
Hmm.. I'm not sure but I think it depends. If *str is holding an address which is located in the heap, then, it will be stored in the heap. But if *str is holding an address which is located in stack, then, the value will be stored in stack...
It's stored in the program static data area, sometimes known as BSS. This is static data that you MUST NOT modify (all being well you will be prevented anyway). It's not stored in ROM, it's stored in RAM, but it shouldn't be changed because you will get undefined behaviour.