I was going through Beej’s Guide to Network Programming and on Page45 the following piece of code was written;
struct pollfd *pfds = malloc(sizeof *pfds * fd_size);
I was wondering if it should be
struct pollfd *pfds = malloc(sizeof(struct pollfd) * fd_size);
Since malloc returns a pointer to a memory block of the specified size.
Since *pfds is a pointer its size will be either 4 or 8 bytes, so I can't understand why its size is being considered while creating the array.