ramu said:
char *str;
str="hello";
str='b';
What's wrong in this? Am getting segmentation fault.
What's wrong with it is that you're not showing us the actual code
that's causing the segmentation fault. Please post a small, complete,
compilable program that exhibits the problem so we don't have to
guess.
If your program really contains
str='b';
then you're trying to assign an integer value (98 if you're using an
ASCII system) to a pointer variable. You can't legally do this; you
can explicitly convert an integer to a pointer using a cast, but there
is no implicit conversion. If your compiler allows it anyway (as an
extension), you're setting str to point to address 98, which is
unlikely to make any sense -- but it *probably* won't cause a
segmentation fault unless you try to use the pointer value.
If your program really contains either
*str='b';
or
str[0]='b';
then you should read question 1.32 in the FAQ at <
http://c-faq.com>.