In C, does a cast from char* to void* do anything?

Please have a look at the below mentioned 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 similar without typecasting (char *), then also i feel it will do the same thing? Can someone clarify?

/* Initialize socket structure */
bzero( &serv_addr, sizeof(serv_addr));


Since the first parameter is void *, you only need to cast in C++.

In C this is not necessary, as a void * was introduced1 precisely so that you wouldn't need to cast it to or from other object2 pointers. (Similarly with malloc() and other functions that deal with void *s)

  1. In C89.
  2. Any non-function pointer.

The cast is not needed, since bzero() accepts void* as the first argument and AnyType* can be implicitly converted to void*.

Need Your Help

Unable to determine the provider name for connection of type 'System.Data.SqlServerCe.SqlCeConnection' sql-server-ce

i am using the Ado.Net Entity Framework with Code Only (Tutorial at: ADO.NET team blog) and i want to be as much database independent as possible.

How to accomplish scrolling text on Twitter home page?

html css twitter

On the twitter home page (not logged in), there a scrolling text in the middle below the logo. How is this accomplished? It stops scrolling when mouseover and also has a popup dialog on relevant te...