It is from the book "C Primer Plus" 4.2.2 String I'm using MAC Xcode to try the example code myself.
Here is the code:
#include <stdio.h>
#define PRAISE "You are an extraordinary being."
int main(void)
{
char name[1];
printf("What\'s your name?\n");
scanf("%s", name);
printf("Hello, %s. %s\n", name, PRAISE);
return 0;
}
when I input "aaaaaaaaaaaaa", intotal 13 letters, the screen shows:
libdyld.dylib`dyld3::MachOFile::forEachLoadCommand:
0x7fff697aa8a8 <+0>: pushq %rbp
0x7fff697aa8a9 <+1>: movq %rsp, %rbp
0x7fff697aa8ac <+4>: pushq %r15
0x7fff697aa8ae <+6>: pushq %r14
0x7fff697aa8b0 <+8>: pushq %r13
0x7fff697aa8b2 <+10>: pushq %r12
0x7fff697aa8b4 <+12>: pushq %rbx
0x7fff697aa8b5 <+13>: subq $0x28, %rsp
0x7fff697aa8b9 <+17>: movb $0x0, -0x29(%rbp)
0x7fff697aa8bd <+21>: movq %rdx, %r12
0x7fff697aa8c0 <+24>: movq %rsi, %rbx
0x7fff697aa8c3 <+27>: movq %rdi, %r15
-> 0x7fff697aa8c6 <+30>: movl (%r15), %edx
0x7fff697aa8c9 <+33>: cmpl $0xfeedface, %edx ;
imm = 0xFEEDFACE
0x7fff697aa8cf <+39>: je 0x7fff697aa8e3 ;
<+59>
0x7fff697aa8d1 <+41>: cmpl $0xfeedfacf, %edx ;
imm = 0xFEEDFACF
Diagnostics::error(char const*, ...)
0x7fff697aa9a2 <+250>: addq $0x10, %rsp
0x7fff697aa9a6 <+254>: addq $0x28, %rsp
0x7fff697aa9aa <+258>: popq %rbx
0x7fff697aa9ab <+259>: popq %r12
0x7fff697aa9ad <+261>: popq %r13
0x7fff697aa9af <+263>: popq %r14
0x7fff697aa9b1 <+265>: popq %r15
0x7fff697aa9b3 <+267>: popq %rbp
0x7fff697aa9b4 <+268>: retq
I omitted some codes above for briefty.
If I input more letters, say 20 "a", It returns: error: memory read failed for 0x7fff00616000
If I change the fifth line into: char name[2];
and input 14 characters, it returns the same result.
similarly, If I change the fifth line into: char name[3];
and input 15 characters, it returns the same result.
I know it has something to do with the size of the aaray, however, I have no idea how the number in the bracket is connected to the corresponding number of input characters. Could anyone explain it with details?