2 2 votes char a[]="gateoverflow"; char *p="gateoverflow"; Why even though both are same way if representing string .By second way we cannot change the value??? Programming in C + – saipriyab 685 views answer comment Share Follow Print See all 4 Comments 4 4 Comments reply joshi_nitish commented Nov 20, 2017 reply Follow flag beacuse second one char *p="gateoverflow"; is string constant, and is stored in read-only memory section where you can access it but can't modify it. 0 0 replyShare Shubhanshu commented Nov 20, 2017 reply Follow flag If you want to assign a new string constant to *p then it is allowed but if you want to perform changes in existing string constant then it will give SEGFAULT. So it depends on in what context you want to change the value of *p. 0 0 replyShare saipriyab commented Nov 20, 2017 reply Follow flag where does char a[] will be stored 0 0 replyShare kirti_k commented Nov 20, 2017 i edited by kirti_k Nov 22, 2017 reply Follow flag a[] is stored in read-write area so we can modify that. 0 0 replyShare Please log in or register to add a comment.
0 0 votes 1. char a[]="gateoverflow"; "gateoverflow" is stored in Stack Frame, which is read-write memory, hence you can easily modify the contents of the string. 2. char *p="gateoverflow"; the location of "gateoverflow" is in the executable, and the location a points to, is in the executable. The data in the executable image is read-only, hence you can't modify it. ref: https://stackoverflow.com/questions/1011455/is-it-possible-to-modify-a-string-of-char-in-c# MIRIYALA JEEVAN KUMA answered Jan 19, 2018 MIRIYALA JEEVAN KUMA comment Share Follow 0 reply Please log in or register to add a comment.