I thought the stack in x86_64 would grow down hence from the max. address of the processes virtuell memory till the end of the stack size (https://www.google.com/url?sa=i&url=https%3A%2F%2Fen.wikibooks.org%2Fwiki%2FX86_Disassembly%2FThe_Stack&psig=AOvVaw3PNsHC2wRGe3XfCCsCi9Kd&ust=1631093147793000&source=images&cd=vfe&ved=0CAkQjRxqFwoTCNiH6c_F7PICFQAAAAAdAAAAABBY).
However in the following C programm the the first char of b
, which I thought should be pushed on the stack after a
and thereby should have a lower address, can be accessed by adding a positive offset instead of a negative one. Why is that?
I also don't understand why the addresses of the pointers to the stings a
and b
as well as the long long int c
are stored ad much higher addresses. Whats in between the 0x7ff... and the 0x55f... addresses? A gap in the Stack?
#include <stdio.h>
int main() {
char *a = "abcdefg";
char *b = "mnopqrs";
printf("address a: %p\n", a);
printf("address &a: %p\n", &a);
printf("address b: %p\n", b);
printf("address &b: %p\n", &b);
printf("Char at addr %p: %c\n", a+8, *(a+8));
long long c = 0;
printf("address c: %p\n", &c);
return 0;
}
Output:
address a: 0x55fa2e1c8004
address &a: 0x7ffc148d29b0
address b: 0x55fa2e1c800c
address &b: 0x7ffc148d29b8
Char at addr 0x55fa2e1c800c: m
address c: 0x7ffc148d29c0