The stack should grow to a low address, why the result of my code test is to grow to a high address

2756 views stack
-3

#include <stdio.h>

int main() {
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    printf("%p\n", &a);
    printf("%p\n", &b);
    printf("%p\n", &c);
    printf("%p\n", &d);

    return 0;
}

The results is: 0x7fff822a2678 0x7fff822a267c 0x7fff822a2680 0x7fff822a2684

answered question

1 Answer

3

Does this answer your question Does stack grow upward or downward? ?

The behavior of stack (growing up or growing down) depends on the application binary interface (ABI) and how the call stack (aka activation record) is organized. Throughout its lifetime a program is bound to communicate with other programs like OS. ABI determines how a program can communicate with another program. The stack for different architectures can grow the either way, but for an architecture it will be consistent. Please check this wiki link. But, the stack's growth is decided by the ABI of that architecture.

posted this

Have an answer?

JD

Please login first before posting an answer.