+ 1

(struct node *)malloc (sizeof(struct node)) what is the use of "*"in it?

27th Jul 2018, 3:10 PM
Keerthana
Keerthana - avatar
2 Answers
+ 9
Keerthana The (struct node*) is a cast, which is a way to tell the compiler that you want to treat the value returned by malloc as a pointer to a structure.
27th Jul 2018, 3:43 PM
Mohammad Amir Aqeel
Mohammad Amir Aqeel - avatar
+ 2
malloc returns pointer of newly allocated memory.. and you are typecasting that memory to pointer only... that's why it is * inside type conversion... for more info: http://www.cplusplus.com/reference/cstdlib/malloc/
27th Jul 2018, 3:40 PM
Ketan Lalcheta
Ketan Lalcheta - avatar