cz when u do char p[]="hello" compiler automatically allocates enough
memory(6 charc here) and puts your string there......

but whn u do char*a="hello" then its complr dependent where d string will be
stored....some compiler stores it in a special location in data segmnt whch
is (read only )so modifying the string is error....other compiler stores it
in write allowed memory so u can alter d string there.......
On Sun, Aug 28, 2011 at 5:02 PM, rohit <raman.u...@gmail.com> wrote:

> Why does the following code not give an error?
>
> #include<stdio.h>
> void fun(char *a) //array decays to pointer here
> {
>      a[0] = 'a';
>      printf("%s\n",a);
>
>
> }
> int main()
> {
>     char p[]="hello";
>     fun(p);
>     getch();
> }
>
> if i write something like this in main
>
> char *arr="hello"
> arr[0] = 'r';  //this gives runtime error and i know why
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/rxboAmI8lEUJ.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 

       Regards
 Himanshu Kansal
   Msc Comp. sc.
(University of Delhi)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to