In this code I passed a character pointer reference to function test and in function test I malloc size and write data to that address and after this I print it and got null value.
#include <stdio.h>
#include <stdlib.h>
void test(char*);
int main()
{
char *c=NULL ;
test(c);
printf("After test string is %s\n",c);
return 0;
}
void test(char *a)
{
a = (char*)malloc(sizeof(char) * 6);
a = "test";
printf("Inside test string is %s\n",a);
}
output:
Inside test string is test
After test string is (null)