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)ので、 の値になりますdweeb[0]

dweeb+0 = 0+dweeb なので、 と書くこともできます0[dweeb]


よく見ると0engineers関数に 2 番目の引数として渡すと0x0、配列の場所としてアドレスが使用されますdweeb。のように、そのアドレスを間接参照することdweeb[0]は未定義の動作です。最も可能性の高い結果は、プログラムがクラッシュすることです。実際に表示される可能性が高いのは次のとおりです。

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

0「括弧の間に入れるとどうなるか」または「の値としてdweep[ ]渡すとどうなるか」の場合、あなたが何を求めているのかわかりません0dweep

于 2013-03-29T16:33:09.797 に答える