We have the following:
typedef struct {
char *p ;
} data_structure ;
void f(data_structur e *data)
{
char *r = malloc(16) ;
data->p = r ;
return ;
}
Assuming that malloc returns a non-NULL pointer, data->p will
point to a valid memory region for as long as data is not released. Is
this correct? I know that when f() returns the value of r becomes
undefined, but I assume that whatever it was pointing to will be left
untouched.
typedef struct {
char *p ;
} data_structure ;
void f(data_structur e *data)
{
char *r = malloc(16) ;
data->p = r ;
return ;
}
Assuming that malloc returns a non-NULL pointer, data->p will
point to a valid memory region for as long as data is not released. Is
this correct? I know that when f() returns the value of r becomes
undefined, but I assume that whatever it was pointing to will be left
untouched.
Comment