0

I am trying to learn what is the difference between:

  1. int *p = malloc(3 * sizeof(int)); AND

  2. int *p = (int*)malloc(3 * sizeof(int));

when initializing a dynamic array in C, and I can't get it, any help?

pzii22
  • 1
  • 3

1 Answers1

1

In C there's no need for such operation, which is called cast, because a void* pointer is implicitly convertible to any kind of pointer.

In C++ you would require it because there's no such implicit conversion, but you will be using new instead that malloc, which wouldn't require it at all.

Jack
  • 131,802
  • 30
  • 241
  • 343