Why does this function accept the `const char *` parameter instead of the `char *` parameter?

Noob C questions:

#include <sys/types.h> 
#include <sys/socket.h> 
#include <netdb.h> 
int 
getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res)

void 
freeaddrinfo(struct addrinfo *ai)

Taken from http://www.nxmnpg.com/3/getaddrinfo . Namely, I am wondering why this is not just getaddrinfo (char * hostname) and instead is a constant.

I have an idea what a pointer is. It seems to me that almost all functions in C prefer pointers passed only to variables, is this true?

+3
source share
2 answers

const - , , , const, . , (;

+3

C ; (char), (char). , (long) API-, , , C, (long) ( , return ed).

+1

All Articles