adrTuIPKJ44 adrTuIPKJ44 - 1 year ago 88
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 :


or do I have to do it like:

char *tab[10];


or, is it another way ?


Answer Source

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


without declaring it first

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download