S
squid
I have a small program that passes a pointer to a function, the
function uses malloc to allocate some memory for it. When I return
the pointer in the function return value I can use it in the calling
function. But I am unable to use the pointer I passes as a
parameter. I am using Visual Studio C++ Express Edition. The program
compiles and runs.
#include <stdio.h>
#include <stdlib.h>
char * getbuff(char *);
void main(void)
{
char *a, *b;
a = 0, b = 0;
b = getbuff(a);
return;
}
char * getbuff(char* p)
{
char * buff;
buff = (char *) malloc(sizeof(char) * 8);
p = buff;
return buff;
}
function uses malloc to allocate some memory for it. When I return
the pointer in the function return value I can use it in the calling
function. But I am unable to use the pointer I passes as a
parameter. I am using Visual Studio C++ Express Edition. The program
compiles and runs.
#include <stdio.h>
#include <stdlib.h>
char * getbuff(char *);
void main(void)
{
char *a, *b;
a = 0, b = 0;
b = getbuff(a);
return;
}
char * getbuff(char* p)
{
char * buff;
buff = (char *) malloc(sizeof(char) * 8);
p = buff;
return buff;
}