int *p,n; char *q,*g,ch; 下列________语句是不合适或不正确的.\x05A.p = &n; g = p = &ch;\x05\x05\x05B.p = &n; q = &ch; C.p = &n; g = &ch;\x05\x05\x05D.p = &n; q = &ch; g = p;我知道B C对的,D肯定错,但对A中这个连等 g = p = &ch;
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 23:47:55
int *p,n; char *q,*g,ch; 下列________语句是不合适或不正确的.\x05A.p = &n; g = p = &ch;\x05\x05\x05B.p = &n; q = &ch; C.p = &n; g = &ch;\x05\x05\x05D.p = &n; q = &ch; g = p;我知道B C对的,D肯定错,但对A中这个连等 g = p = &ch;
int *p,n; char *q,*g,ch; 下列________语句是不合适或不正确的.
\x05A.p = &n; g = p = &ch;\x05\x05\x05B.p = &n; q = &ch;
C.p = &n; g = &ch;\x05\x05\x05D.p = &n; q = &ch; g = p;
我知道B C对的,D肯定错,但对A中这个连等 g = p = &ch; 有疑问,这是个什么过程呢?
int *p,n; char *q,*g,ch; 下列________语句是不合适或不正确的.\x05A.p = &n; g = p = &ch;\x05\x05\x05B.p = &n; q = &ch; C.p = &n; g = &ch;\x05\x05\x05D.p = &n; q = &ch; g = p;我知道B C对的,D肯定错,但对A中这个连等 g = p = &ch;
连等是可以的,但是A选项是错的,因为g指向字符型,p指向整型.
把p改成q后过程如下:
g = q = &ch中只有一个运算符,等号,所以优先级是一样的,而等号的结合性是从右向左的(也就是等式从右往左计算),所以g = q = &ch等同于g =( q = &ch),赋值表达式的返回值是等号左边变量的值,故g和q都指向ch