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:

  1. int * a; // then use it to track an array

  2. 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

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

asp.net mvc - How to attach sql database to a javascript graph -

c# - How to know the number of Threads created and limit the Tasks accordingly -