KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have this piece of code in C: int q = 10; int s = 5; int a[3]; printf("Address of a: %d\n", (int)a); printf("Address of a[1]: %d\n", (int)&a[1]); printf("Address of a[2]: %d\n", (int)&a[2]); printf("Address of q: %d\n", (int)&q); printf("Address of s: %d\n", (int)&s); The output is: Address of a: 2293584 Address of a[1]: 2293588 Address of a[2]: 2293592 Address of q: 2293612 Address of s: 2293608 So, I see that from a to a[2] , memory addresses increases by 4 bytes each. But from q to s , memory addresses decrease by 4 byte. I wonder 2 things: Does stack grow up or down? (It looks like both to me in this case) What happens between a[2] and q memory addresses? Why there is a big memory difference there? (20 bytes). Note: This is not homework question. I am curious on how stack works. Thanks for any help.
Tags (comma-separated)
Save Edits
Cancel