0 votes 0 votes #include <stdio.h> main() { char *p = "Sanfoundry C-Test"; p[0] = 'a'; p[1] = 'b'; printf("%s", p); } Others programming-in-c pointers + – shiva0 asked Jul 18, 2018 edited Mar 14, 2019 by adeebafatima1 shiva0 2.2k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes A string literal cannot be modified in C. Hence, there should be an error. If you run it, you will most probably get a segmentation fault. mohitjarvissharma answered Jul 18, 2018 mohitjarvissharma comment Share Follow See all 2 Comments See all 2 2 Comments reply shiva0 commented Jul 19, 2018 reply Follow Share i didn't understand can you explain once again please....! 0 votes 0 votes mohitjarvissharma commented Jul 19, 2018 reply Follow Share char *p = "Sanfoundry C-Test"; You define a string literal this way in C. And you should know that string are immutable in C ..i.e. you cannot modify a string after you have defined it. If you define it in this way: char p[] = "Sanfoundry C-Test"; , this will work. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes i think there is error in this code Because in the question p is a pointer to a charcter and trying to manipulate whole string that trying to do a[0]=a,a[1]=b. imnitish answered Jul 18, 2018 imnitish comment Share Follow See all 0 reply Please log in or register to add a comment.