Exercise Sheet 5, question12

In solution for exercise 12.: Calendar, part c, line 47, why is

malloc(sizeof(char) * 256)

passed as an argument to event_init? Doesn’t event_init only accept a title with the data type char* as a parameter?

1 Like

Indeed, the parameter needs to have char* type. malloc() returns a pointer of type void*, which is automatically converted into any other pointer type (except for function pointers). This mechanism is similar to that of chapter 4.8.1 in the lecture notes.

1 Like