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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.