Reputation: 2130
I was wondering why I get these memory addresses in this simple program.
#include <stdio.h>
int main() {
char *a = "buffera";
char *b = "bufferbb";
printf("%p %p\n", a, b);
return 0;
}
Output I get is.
00403064 0040306C
Supposedly each character occupies one byte in memory (two hex numbers), then if the string a
occupy 7 + 1 = 8 bytes in memory and the address of a
starts at 0x00403064, then according to me it should end at 0x00403079 and not at 0x0040306B.
Upvotes: 0
Views: 69
Reputation: 81936
0x00403064 + 0x8 == 0x0040306C
Note that these numbers are in hexadecimal.
But either way, while these strings can't overlap, they don't need to be placed anywhere near each other in memory.
Upvotes: 1
Reputation: 49813
0043064 + 8 = 0040306C; I don't know where you get 00403079 from.
Upvotes: 4