-1

I'm studying about realloc and the syntax for it is:

    void *realloc(void *ptr, size_t size);

but in many example of realloc being used the syntax they use is different ? for example

    str = (char *) realloc(str, 25);

Can some one explain why there is such a difference ? why is there an extra "(char *)" in front of the realloc?

Oh Oh
  • 33
  • 3
  • C is less strict with type checking than C++. So, if you want to compile code for both C and C++ (which happens quite often), you add the cast to make the type checking of C++ happy, while it is not strtictly needed for C, which does not really care if you shoot yourself in the foot :) – BitTickler May 12 '22 at 13:12
  • Do you understand the difference between `int square(int x);` and `square(5)`? – user253751 May 12 '22 at 13:43

0 Answers0