On Jul 27, 11:27*am, squid <jvstew...@gmail.com> wrote:
Oh. My. Goodness. There is so much wrong here, I don't know where to
start.
I guess first, you should post in comp.lang.c, as you are coding in
the strict C subset.
> I am trying to pass a pointer to a function and in the function
> allocate some memory for it using malloc
Do not use malloc in a C++ program. Use new.
> and then using it in the
> calling function. *If I return the pointer in the function return
> value and assign it to a pointer variable when I call the function it
> works.
> *But when I try to use the pointer I sent as a parameter it
> says the pointer variable is undefined and I am unable to access the
> allocated memory.
What book are you using that doesn't discuss the fact that C++ uses
pass-by-value?
>
> #include <stdio.h>
> #include <stdlib.h>
>
> char * getbuff(char *);
>
> void main(void)
In C++, main returns int. Period.
> {
> char *a, *b;
>
> b = getbuff(a*);
Won't compile. Bad syntax.
>
> return;
>
> }
>
> char * getbuff(char * p)
> {
> * * * * char * buff;
> * * * * buff = (char *) malloc(sizeof(char) *
;
> * * * * p = buff;
> * * return buff;
>
> }