If I have code like this:
int e;
int* f;
int main() {
int a, b, c;
int* d;
}
Where in memory are these variables stored?
And, what’s the problem with defining global variables (out of a function, like main in this case)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
a,b,c and d will exist on the stack. If you were to create an instance of an int (with malloc or new), that would go on the heap – but the pointer called ‘d’ would still exist on the stack.
e and f are allocated space in the memory space of the app, in the so-called ‘Data segment’ – see:
You also asked about stack size: that’s configured by the compiler, see here: