0

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

adrTuIPKJ44
  • 2,793
  • 2
  • 9
  • 8

1 Answers1

1

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

Community
  • 1
  • 1
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124