edited by
2,163 views
0 votes
0 votes
#include <stdio.h>
    main()
    {
        char *p = "Sanfoundry C-Test";
        p[0] = 'a';
        p[1] = 'b';
        printf("%s", p);
    }

 

edited by

2 Answers

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.
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.

Related questions

2 votes
2 votes
1 answer
3
0 votes
0 votes
1 answer
4
Psnjit asked Jan 12, 2019
1,138 views
main(){unsigned int i= 255;char *p= &i;int j= *p;printf("%d\n", j);unsigned int k= *p;printf("%d", k);} Both the outputs are -1. I have even tried with - int i = 255(3rd ...