In C, does casting from char * to void * do something?
Please take a look at the below code snippet and tell me the difference?
int main()
{
struct sockaddr_in serv_addr, cli_addr;
/* Initialize socket structure */
bzero((char *) &serv_addr, sizeof(serv_addr));
}
Now, what if I do something like this without styling (char *)
, then also I feel like it will do the same? Can anyone clarify?
/* Initialize socket structure */
bzero( &serv_addr, sizeof(serv_addr));
+2
a source to share
2 answers
Since the first parameter is void *
, you only need to execute it in C ++.
In C, this is optional, since 1void *
was introduced exactly so that you didn't have to cast it into a pointer or from other pointers 2 (Similar with and other s- related functions )malloc()
void *
- The C89.
- Any non-functional pointers.
+4
a source to share