> > "What i am saying is >>> >>> if i write it like >>> p[5]= 'a'; >>> >>> Then the compiler will raise an error . Because the memory where the >>> string constant "Hello world" gets stored is read only. >>> >>> But it i do it like >>> >>> char s[] = "hello world",*p; >>> >>> p=s; >>> >>> p[5]='a'; >>> >>> It is valid becoz the string is now stored in stack segment of program . >>> >>> So my doubt is where the string constant gets stored exactly in the first >>> case...and why it cant be altered.." >> >> When you declare a string using pointer, the contents are stored in *read only memory*. So if u try to alter it, it will show error, but when u create an array of same string ,compiler copies the string from read only memory to stack where you can modify it. So when u alter it, it shows no error. -- Thanks and Regards *Devansh Gupta* *B.Tech Third Year* *MNNIT, Allahabad*
-- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
