Q: What, if trying to copy a string of 10 bytes to another string declared as 5 bytes, happens?
Answer:
char *a=(char *)malloc(sizeof(char)*5);
char b[5];
char *str="Hello World";
cout<
cout<
分かるようにcopy 先が足りない場合は、あたかも割り当てられてるようにcopy している。
結果としては、どちらもHello Wolrdが出力されるが、memory動作は不安定である。
From Bloomberg phone interview.