The answer to your problem is ***"Its a compiler Issue or requirement".***
A void pointer in C can be assigned to any pointer without an **[explicit type-cast][1]**.C Language implicitly casts void* to any type, so the cast will be done automatically.
Thus your above code will run absolutely fine in C .Check the error-free/warning free running of your code in C [HERE][2].
But In the same code compiled in C++,this will give error [http://ideone.com/ibB3Y][3]:
invalid conversion from ‘void*’ to ‘tree*’
So in c++ ,implicit conversion of void* to tree * is not allowed/done automatically,explicit type casting is required,So you must explicitly type cast the void pointer returned by malloc to tree* type to fit it into temp .Refer **[this][4]**
temp=(tree*)malloc(sizeof(struct tree));/*Explicit Casting required*/
*Please Note Some c++ compiler version ,**C++1x** and even the The [C99 standard][5] does not required the cast.*
Hope this help!
[1]: http://en.wikipedia.org/wiki/Type_conversion#Explicit_type_conversion
[2]: http://ideone.com/DQeJV
[3]: http://ideone.com/ibB3Y
[4]: http://ideone.com/7UPln
[5]: http://en.wikipedia.org/wiki/C99

The answer to your problem is ***"Its a compiler Issue or requirement".***
A void pointer in C can be assigned to any pointer without an **[explicit type-cast][1]**.C Language implicitly casts void* to any type, so the cast will be done automatically.
Thus your above code will run absolutely fine in C .Check the error/warning error-free/warning free running of your code in C [HERE][2].
But In C++,this will give error [http://ideone.com/ibB3Y][3]:
invalid conversion from ‘void*’ to ‘tree*’
So in c++ ,implicit conversion of void* to tree * is not allowed/done automatically,explicit type casting is required,So you must explicitly type cast the void pointer returned by malloc to tree* type to fit it into temp .Refer **[this][4]**
temp=(tree*)malloc(sizeof(struct tree));/*Explicit Casting required*/
*Please Note Some c++ compiler version ,**C++1x** and even the The [C99 standard][5] does not required the cast.*
Hope this help!
[1]: http://en.wikipedia.org/wiki/Type_conversion#Explicit_type_conversion
[2]: http://ideone.com/DQeJV
[3]: http://ideone.com/ibB3Y
[4]: http://ideone.com/7UPln
[5]: http://en.wikipedia.org/wiki/C99

The answer to your problem is ***"Its a compiler Issue or requirement".***
A void pointer in C can be assigned to any pointer without an **[explicit type-cast][1]**.C Language implicitly casts void* to any type, so the cast will be done automatically.
Thus your above code will run absolutely fine in C .Check the error/warning free running of your code in C [HERE][2].
But In C++,this will give error [http://ideone.com/ibB3Y][3]:
invalid conversion from ‘void*’ to ‘tree*’
So in c++ ,implicit conversion of void* to tree * is not allowed/done automatically,explicit type casting is required,So you must explicitly type cast the void pointer returned by malloc to tree* type to fit it into temp .Refer **[this][4]**
temp=(tree*)malloc(sizeof(struct tree));/*Explicit Casting required*/
*Please Note Some c++ compiler version ,**C++1x** and even the The [C99 standard][5] does not required the cast.*
Hope this help!
[1]: http://en.wikipedia.org/wiki/Type_conversion#Explicit_type_conversion
[2]: http://ideone.com/DQeJV
[3]: http://ideone.com/ibB3Y
[4]: http://ideone.com/7UPln
[5]: http://en.wikipedia.org/wiki/C99