There is a FILE* "sockfd" that provides a remote connection over a socket. What is the correct way to send the value of the int variable "data" across the connection?



A.write(sockfd, data, sizeof(int))



B.write(*sockfd, &data, 4)



C.write(sockfd, &data, sizeof(int))



D.write(*sockfd, data, 4)

Respuesta :

Answer:

C.write(sockfd, &data, sizeof(int))

Explanation:

The variable sockfd is a pointer to the socket file descriptor. In order to write an int data over the socket we can use the write API.

write takes the following arguments:

- pointer to socket file descriptor

- starting address of memory location containing the data to be written

- sizeof the data to be written.

In our case this will correspond to:

write(sockfd, &data, sizeof(int));

where data is the variable containing the integer data.