J
Johs32
I have a struct "my_struct" and a function that as argument takes a pointer
to this struct:
struct my_struct{
struct my_struct *new;
};
void my_func(struct my_struct *new);
I have read that there is no difference between giving this function a
pointer to a struct or the address of a struct:
1) passing a pointer to a struct:
struct my_struct *pp;
my_func(pp);
2) passing an address of a struct
struct my_struct new;
my_func(&new);
is it true that both of the above options are correct?
Another thing I have been told that if I do:
struct my_struct *p;
p->new = NULL;
I should first malloc "p" because a pointer should be initialized before
using "->", but is that not what p->new = NULL does (initialising new) or
do I first need to malloc "p" before I initialize new?
to this struct:
struct my_struct{
struct my_struct *new;
};
void my_func(struct my_struct *new);
I have read that there is no difference between giving this function a
pointer to a struct or the address of a struct:
1) passing a pointer to a struct:
struct my_struct *pp;
my_func(pp);
2) passing an address of a struct
struct my_struct new;
my_func(&new);
is it true that both of the above options are correct?
Another thing I have been told that if I do:
struct my_struct *p;
p->new = NULL;
I should first malloc "p" because a pointer should be initialized before
using "->", but is that not what p->new = NULL does (initialising new) or
do I first need to malloc "p" before I initialize new?