c++ - Passing char array to function -


i have call method following signature:

int sendto(const void* buffer, int length, const socketaddress& address, int flags=0);

  • my first question is:

    what const void* buffer mean? intention is: means constant (unmodifiable) pointer can point anything. ist somehow right?

  • second question:

the purpose of method is, obviously, send data on socket. first parameter data, second length of data. if want pass string "hello" first parameter, how this?

my idea:

char hello_str[1024] = "hello" socket.sendto(hello_str, sizeof(hello_str),.....); 

would work? way have way big char array.
how can create array right size?

recall const protect left side unless there's nothing it's left, protects right side. applying code we'll const protecting void* buffer. means value points cannot modified:

enter image description here

the first pointer const variable - pointer can changed.
second const pointer variable - value can changed.

this work, can try it.
, others answered, creating right size done by:

char hello_str[] = "hello";


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -