a is a pointer to somewhere where "string" is written..
p is a pointer to somewhere where "new sring" is written.
temp is made to point at same location to which a is currently pointing that
is at "string"
by malloc some new memory is alloted and a is made to point to thast
memory.. temp remains to point at "string" it doesnt get changed..
so when you are copying temp to p.. string gets copied not "new string" of
a..

On Tue, Jul 26, 2011 at 12:19 AM, swetha rahul <[email protected]>wrote:

> *void main()
> *{*
> int i;
> char *a="String";
> char *p="New String";
> char *Temp;
> Temp=a;
> a=malloc(strlen(p) + 1);
> strcpy(a,p);
> p = malloc(strlen(Temp) + 1);
> strcpy(p,Temp);
> printf("(%s, %s)",a,p);
> free(p);
> free(a);
> } *
> *
> *
> *
> *
> *output is (New String,String)*
> *
> *
> *how does Temp retains "String" even after New String is copied in a? Is
> it not pointing to the same location?pls explain*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

Reply via email to