I am posting two codes down. In the first code an unexpected output is coming "ASH-2". The output which must be coming is "ASH35". In the second code, output comes out to be "ASH35". Now if i remove the ' printf("ASH"); ' line in the first code, value 35 gets printed.
Can anyone help me in this unexpected behaviour, thank you in advance for looking into my matter.
//CODE 1
int* fun()
{
int k;
k=35;
return (&k);
}
int main()
{
int *j;
j=fun();
printf("ASH");
printf("%d",*j);
return 0;
}
//CODE 2
int fun()
{
int k;
k=35;
return (k);
}
int main()
{
int j;
j=fun();
printf("ASH");
printf("%d",j);
return 0;
}