In fn, ptr is a local variable passed by value. Changing ptr in the
function does not change anything in main.
Don

On Mar 31, 10:35 pm, navin <[email protected]> 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 [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