0

#include<stdio.h>
#include<string.h>
void fn (int *ptr)
{
static int val=100;
ptr=&val;
}
main()
{
int i=10;
printf("%d", i);
fn(&i);
printf("%d", i);
getch();
}

The output of the above code is 10 10.
why not 10 100?
What is happening inside fn?

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Adak
0

ptr is being given a new address, in the assignment statement ptr=&val, in fn(). It no longer has anything to do with i.

Edited by Adak: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.