The question is about looping through the following structure
Code:
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
#ifndef _POSIX_C_SOURCE
#define h_addr h_addr_list[0] /* address, for backward compatiblity */
#endif /* !_POSIX_C_SOURCE */
};
ive seen people use
Code:
//with pointers
for( char const*const* alias = hp->h_aliases;
*alias != NULL;
++alias
and
Code:
// with indexing
for( int i=0;
hp->h_aliases[i];
++i)
When you use a for loop using pointers this case, why is the person explicit about NULL, but with indexing, it's implicit? ie not using
hp->h_aliases[i] != 0