使用本指南,我被告知数组是通过引用传递的。当结构看起来像这样时,这成立:
struct Person{
char* name;
int id;
}
但是当结构看起来像:
struct Person{
char name[20];
int id;
}
使用 seconds 结构时,name
数组按值复制:
struct Person p1 = {"John", 1234};
struct Person p2 = p1;
p2.name[0] = 'L';
// p1.name[0] is still 'K'
为什么会这样?