Will p = (users *)malloc(sizeof(users)); create memory for the playlist structure too? Also how can I reference playlist.album using p?
struct playlist_ {
int album;
int track_num;
struct playlist_ *next;
};
struct users_ {
int user_ID;
struct playlist_ playlist;
struct users_ *next;
};
typedef struct playlist_ playlists;
typedef struct users_ users;
users *p;
p = (users *)malloc(sizeof(users));
playlistis a member ofusers_, so it forms part of the allocated space. So to answer your question: yes.[Incidentally, you don’t need to (and shouldn’t) cast the result of
malloc.]Depends what you mean by “reference”. Assuming you just mean “access”, then this: