adrTuIPKJ44 adrTuIPKJ44 - 1 month ago 5
C Question

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

Answer

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

gethostbyname("10.11.22.4");

without declaring it first

Comments