0

For example:

int *p = malloc(sizeof(int));

Is the above equivalent to the following?:

int *p = (int*)malloc(sizeof(int));

What does (int*), which looks like redundant, mean here?

Youjun Hu
  • 595
  • 3
  • 15
  • 1
    It is indeed redundant. It would make a sense to use the casting in the following statement p = (int*)malloc(sizeof(int)); This makes the code self-documented because it is not necessary that p indeed has the type int * and not for example char *. – Vlad from Moscow Mar 01 '22 at 13:32

0 Answers0