adrTuIPKJ44
adrTuIPKJ44

Reputation: 3163

Using gethostbyname function

I have a piece of code that use gethostbyname() function, which is defined this way:

struct hostent *gethostbyname(const char *name);

My question is very simple, is it possible to directly put the char value like this :

gethostbyname("10.11.22.4");

or do I have to do it like:

char *tab[10];

gethostbyname(*tab);

or, is it another way ?

Thanks

Upvotes: 0

Views: 289

Answers (1)

CIsForCookies
CIsForCookies

Reputation: 12837

As said here the type of a string literal "this is a string literal" is an array of const char. Arrays decay to pointers, so this means you can use

gethostbyname("10.11.22.4");

without declaring it first

Upvotes: 1

Related Questions