in fn1
ptr is pointer to integer i and you are changing content of i by using *ptr
from 10 to 100

in fn
ptr is pointer to integer i and you are changing pointer ptr by pointing to
val(now ptr no more point to integer i).so here only pointer is changing not
value.

am i clear to you?

On Fri, Apr 1, 2011 at 9:05 AM, navin <navin.myhr...@gmail.com> wrote:

> see this c code.
>
> #include<stdio.h>
>
> void fn (int *ptr)
> {
>       const int val=100;
>       ptr=&val;
> }
> void fn1(int *ptr)
> {
>       *ptr = 100;
> }
>
> main()
> {
>       int i=10;
>       printf("%d ", i);
>       fn(&i);
>       printf("%d ", i);
>       fn1(&i);
>       printf("%d ", i);
> }
>
> What is the difference between fn and fn1?
> I expected the output to be 10 100 100
> but it came as 10 10 100.
> can anyone explain what happens in fn.
> why 100 in fn is not stored in ptr.
>
> --
> 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.
>
>


-- 
Pankaj Agarwal
B.Tech(Final Year Undergraduate)
Communication and Computer Engineering
LNMIIT,jaipur

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