if an array is defined in the main function will the stack make a pointer in the call stack or will it call the function main in call stack?
Doubt in call stack
@israina27 Your question is not clear enough. But i am explaining what all happens when you define an array in the main function:
Call stack will have the functions in it along with the local variables. So if you define an array in the main function, there may be 2 cases:
- If static memory allocation is done to create the array example int arr[20];
This will be stored in the stack area of the memory. - If you create a dynamic array example int* arr=new int[20]; //memory allocated at runtime
In this case, pointer variable arr will be stored in the stack memory. This variable will store the address of
dynamically allocated memory for the array which will be in the heap memory. So, in short, array will be in the heap memory but the address of this array in heap memory will be contained in int*arr which will be in the stack memory.
Hope this helps
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.