In the following C program,'s' is declared as character pointer and assigned with a string "Fine", now I am trying to replace the first character to 'N' that should result in "Nine". But this program results in runtime error.
#include<stdio.h>
main()
{
char *s = "Fine";
*s = 'N';
printf("%s", s);
}
whereas, if the above program is changed as following, declaring 's' as a character array, the program runs without any error and output will be "Nine"
#include<stdio.h>
main()
{
char s[] = "Fine";
*s = 'N';
printf("%s", s);
}
I do not know the reason behind this issue. It would be great if someone explains me. Thanks in advance.