0

如果您调用如下函数:

coworkers = engineers(1,0,3);
...

int engineers(unsigned char nerd, unsigned char dweeb[], unsigned char derp) {
     printf("Is this the address of dweeb[0]? 0x%x \n", dweeb);
     printf("Is this the value of dweeb[0]? %x \n", dweeb[0]);
} 

Output:
Is this the address of dweeb[0]? 0xfeedbeef
Is this the value of dweeb[0]? 

当我将 0 值传递给 dweeb[] 时,它会变成 dweeb[0] 的值吗?

——我是笨蛋,周五快乐。谢谢

4

1 回答 1

0

dweeb[0]等价于*(dweeb+0)所以是的,它确实变成了 at 的值dweeb[0]

请注意,因为 dweeb+0 = 0+dweeb,您也可以将其写为0[dweeb].


仔细观察,当您将函数作为第二个参数传递0给函数时engineers,发生的情况是该地址0x0将用作数组的位置dweeb。取消引用该地址,如dweeb[0],是未定义的行为。最可能的结果是程序崩溃。您实际看到的更有可能是:

Is this the address of dweeb[0]? 0x0
Segmentation fault

我不确定你在问什么,如果它是“如果我把0括号放在dweep[ ]”中会发生什么或“如果我0作为值传递会发生什么dweep

于 2013-03-29T16:33:09.797 回答