Why is this happening...??
There is an important difference between these definitions:
Code:
char amessage[] = "now is the time"; /* an array */ initializes it. Individual characters within the array may be changed but amessage will always refer to the same storage. On the other hand, pmessage is a pointer, initialized to point to a string constant; the pointer may subsequently be modified to point elsewhere, but the result is undefined if you try to modify the string contents. Please explain to me why this difference occurs. It would be better if the explanation is based on the memory allocation. thanks, thelink |
Hi,
In the declaration /* char *pmessage = "now is the time"; */ you are pointing to a string constant, which cannot be changed. That is why you are getting memory access error while trying to alter its contents. Thanks, |
All times are GMT -5. The time now is 02:55 AM. |