This may or may not be a very simple question, but I would like to know what function to call in order to figure out how many bytes are in an array at any given time. For example, how would I know what to put as the third argument in the send command in the code below?
int *array= new int[500];
memset(array, 0, sizeof(array));
//newsockfd is declared elsewhere in the code
send(newsockfd, array, _______, 0);
The size of an array is constant (it’s just a hunk of memory).
You’ll need to keep track of how many elements of the array are valid yourself, in a separate variable.
As others have noted, the last argument to
memsetshould be the number of bytes you want set to 0 — butarrayis just a pointer, sosizeof(array)will yield only 4 (or 8 on a 64-bit platform). Again, you’ll need to manually pass insizeof(int) * 500(or use a constant for the 500 so you don’t have to update the number in multiple places if it changes).