#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int n = 5;
char str1[n];
char *str2;
char str3[] = "World!";
// dynamically allocate memory for string 2
str2 = malloc(sizeof(char) * n);
// Copy strings into string 1 and 2
strcpy(str2, "Hello");
strcpy(str1, "Oi! ");
// print memory locations
printf("%s -> %p\n", str1, &str1);
printf("%s -> %p\n", str2, &str2);
printf("%s -> %p\n", str3, &str3);
return 0;
}
So why is str1 and str3 lower addresses than str2 when printing memory locations? I thought higher addresses were for the stack and lower addresses for the heap. So if it is because of the reference variables address than why is it higher than str1, when str1 was declared first?