what is the main reason of using malloc() in C -
I am currently using C / C ++ but instead of declaring something var on stack, malloc / new What is the main reason to use Such as: int a;
Or any other example:
-
int * a; // then use it to track an array
-
int a = (int ) malloc (sizeof (int));
Responsibility comes with that flexibility: When you end up with them, if you try to hold on a raw pointer and do it yourself, then it is difficult to correct; So learn (C ++), and use smart pointer and ready-made management type like container to work for you.
Comments
Post a Comment