C中的指针和地址
Pointer and address in C
我的老师在他的演讲 powerpoint 上有这些问题,但没有答案。有人可以帮忙吗。刚接触 c.
If a is an int variable, is it always true that *&a == a ?
If p is an int* variable, is it always true that p == &*p ?
Is it ever meaningful to say **p ?
Is it ever meaningful to say &&a ?
After assigning a = 2 and p = &a, how much is *p**p ?
If furthermore q = &p, how much is **q**p***q ?
最后,a/*p是多少?
If a is an int variable, is it always true that *&a == a ?
它应该,但我找不到明确的说法。
If p is an int* variable, is it always true that p == &*p ?
是 - 在这种情况下,&
和 *
运算符都不会被实际计算。参见 C 2011 标准的 online draft,§
6.5.3.2 ¶ 3.
Is it ever meaningful to say **p ?
是的。多重间接寻址无处不在。您可以拥有指向指针的指针、指向指针的指针、指向指针数组的指针、返回指向指针数组的指针的函数指针等。
Is it ever meaningful to say &&a ?
没有。 &a
的结果不是左值,因此不能对它应用 &
运算符。换句话说,地址的地址是什么?
After assigning a = 2 and p = &a, how much is *p**p ?
应该和a * a
一样,虽然要注意C的tokenizing算法是"greedy",所以你真的 想用空格分隔术语和运算符。
If furthermore q = &p, how much is **q**p***q ?
同样,它应该 与a * a * a
相同,并且再次注意 C 是如何标记表达式的。
我的老师在他的演讲 powerpoint 上有这些问题,但没有答案。有人可以帮忙吗。刚接触 c.
If a is an int variable, is it always true that *&a == a ?
If p is an int* variable, is it always true that p == &*p ?
Is it ever meaningful to say **p ?
Is it ever meaningful to say &&a ?
After assigning a = 2 and p = &a, how much is *p**p ?
If furthermore q = &p, how much is **q**p***q ?
最后,a/*p是多少?
If a is an int variable, is it always true that *&a == a ?
它应该,但我找不到明确的说法。
If p is an int* variable, is it always true that p == &*p ?
是 - 在这种情况下,&
和 *
运算符都不会被实际计算。参见 C 2011 标准的 online draft,§
6.5.3.2 ¶ 3.
Is it ever meaningful to say **p ?
是的。多重间接寻址无处不在。您可以拥有指向指针的指针、指向指针的指针、指向指针数组的指针、返回指向指针数组的指针的函数指针等。
Is it ever meaningful to say &&a ?
没有。 &a
的结果不是左值,因此不能对它应用 &
运算符。换句话说,地址的地址是什么?
After assigning a = 2 and p = &a, how much is *p**p ?
应该和a * a
一样,虽然要注意C的tokenizing算法是"greedy",所以你真的 想用空格分隔术语和运算符。
If furthermore q = &p, how much is **q**p***q ?
同样,它应该 与a * a * a
相同,并且再次注意 C 是如何标记表达式的。