I have two AWS lightsail vps boxes, and I am trying the follow simple C program on both vps to test out the address of local variables.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_one, "one");
strcpy(buffer_two, "two");
printf("buffer_one is at %p\n", buffer_one);
printf("buffer_two is at %p\n", buffer_two);
return 0;
}
On box A(running ubuntu 14.04), it produces something like:
buffer_one is at 0x7ffd1fe3d5a0
buffer_two is at 0x7ffd1fe3d5b0
on box B(running Centos 7.5, it's the following:
buffer_one is at 0x7fffa53678a0
buffer_two is at 0x7fffa5367890
I am surprised because both variables are in the main function, which makes them local variables and consequently they should be stored in the "stack" of the program's address space when running. And if so, the first variable(buffer_one) should be in a "higher" address than the second variable(buffer_two). Indeed, it's the case in B, but why A is the other way around...?