#include<stdio.h>
int * display();
main()
{
printf("\nHello\n");
int * a = display();
printf("%d", *a);
}
int * display()
{
printf("\n Hi \n");
int b = 10;
return &b;
}
Can anyone tell me how does memory allocation work in c?
I'm sure we can access the value of b(in this program), then why can't we access the address of it? I get an error (Segmentation fault).
What is the concept behind it?
I'm a beginner.