what is the difference between static and dynamic and when to use which one ?
Dynamic vs static
Hello @prerak_semwal you have raised the doubt again:
i have just answered your query:
Static arrays are allocated memory at compile time and the memory is allocated on the stack. Whereas, the dynamic arrays are allocated memory at the runtime and the memory is allocated from heap. Stack have limited amount of memory but heaps have all the memory ur system can offer.A static variable can be thought of as a variable that is allocated in memory for the lifetime of during program execution. Even if it is used in a function that is called several times, the same memory space will be utilized for the static variable. The calculated value of this variable will be carried to the next function call too. The concept is useful for applications where the previous active state of a function is required. I never heard of dynamic variable unless we are considering it as a variable which is dynamically allocated.We allocate statically when we know the amount of memory required before execution of the program And we use dynamic allocation when we we don’t know the size of array or how much memory we will require
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.