Dynamic Memory Allocation

I have the following doubts:

  1. What is the difference between compile time and run time?
  2. Can we initialize an array in dynamic Memory allocation just like we do for a variable?
  3. How does dynamic Memory allocation saves memory in case of arrays?
    I mean in both the cases, that is, dynamic and static run, we need to specify the size.
  4. In dynamic Memory allocation of arrays, what will happen if all the spaces are not occupied as specified in the syntax
    int *var= new int(n) ?

Compile time: Errors that occur when you violate the rules of writing syntax are known as Compile-Time errors. This compiler error indicates something that must be fixed before the code can be compiled. ( the red markers we see while we code)
Run time: Errors which occur during program execution(run-time) after successful compilation are called run-time errors. One of the most common run-time error is division by zero also known as Division error. ( ones we get in the error logs after we have complied the code)

int ptr;
ptr = (int
)malloc(n * sizeof(int));
u can use calloc , new

I havent heard of such a thing happening, size of datatype remains the same so how would we be saving on memory on allocating memory for array in either of the ways.
Its just that heap is used for dynamic allocation whereas stack for dynamic allocation

u mean there isnt sufficient space in the heap?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.