2013-03-29 78 views
0

如果调用等的函数:ANSI C - 传递值阵列

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值呆子[]这是否成为呆子[0]的值?

- 我是个大笑,周五快乐。谢谢

回答

0

dweeb[0]相当于*(dweeb+0)所以是的,它确实成为值在dweeb[0]

注意,因为呆子+ 0 = 0 +呆子,你也可以写为0[dweeb]


在仔细一看,当你通过0engineers功能作为第二个参数,什么情况是,该地址0x0将用作阵列dweeb的位置。取消引用该地址(如dweeb[0])是未定义的行为。最可能的结果是程序崩溃。你会怎样实际上看到的是更容易:

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

我不知道你在问什么,如果它是:“如果我把括号0dweep[ ]会发生什么”或“如果我通过会发生什么0作为值为dweep