Hi CLCers,
I coded a function to allocate memory and i am passing a pointer to the
function. The code is compiling but throws error and closes while
executing. The program is as below:
#include<stdio. h>
#include<stdlib .h>
int main()
{
int *p;
void mem_fun(int *i);
mem_fun(p);
printf("%d\n",* p);
getch();
return 0;
}
void mem_fun(int *i)
{
printf("%u\n",i );
i=malloc(sizeof (int));
*i=10;
printf("%d\n",* i);
}
Please help in understanding the problem. Advanced thanks.
Cheers
Shan
I coded a function to allocate memory and i am passing a pointer to the
function. The code is compiling but throws error and closes while
executing. The program is as below:
#include<stdio. h>
#include<stdlib .h>
int main()
{
int *p;
void mem_fun(int *i);
mem_fun(p);
printf("%d\n",* p);
getch();
return 0;
}
void mem_fun(int *i)
{
printf("%u\n",i );
i=malloc(sizeof (int));
*i=10;
printf("%d\n",* i);
}
Please help in understanding the problem. Advanced thanks.
Cheers
Shan
Comment