以下代码段是C11标准§6.5.2.3中的示例:
struct t1 { int m; };
struct t2 { int m; };
int f(struct t1 *p1, struct t2 *p2)
{
if (p1->m < 0)
p2->m = -p2->m;
return p1->m;
}
int g()
{
union {
struct t1 s1;
struct t2 s2;
} u;
/* ... */
return f(&u.s1, &u.s2);
}
Run Code Online (Sandbox Code Playgroud)
根据C11,内部的最后一行g()无效.为什么这样?
int main()
{
printf("Hello World\n");
int x = -10;
unsigned y = 25;
float z = x*y;
printf("x=%d,y=%u,z=%f\n",x,y,z);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我得到以下输出:
你好世界
x=-10,y=25,z=4294967046.000000
我的问题是:对于第二个 printf,我会期望的z=(float) ( (unsigned)(-10)*25 ) = (float) (4294967286 x 25) = (float) 107374182150,我在这里错过了什么?
说所有Python变量都是指向某个数据对象(例如int或list)的指针(以C表示)的指针是否正确?例如a = 5将对象int(5)的地址放入a,其中a有自己的地址,这是无用的(我认为)。
并且在Python中定义了print以打印存储在a中的地址所指向的对象的内容。
在Python中定义了id来打印存储在a中的地址。
这到底是怎么回事?