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/26 22:26:10
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;
xRAoA+{2-/X1&r/di=x XZ(5h ]vŸof_٭zd3>+=7R)e|qgHI@Ō:؝'# 8CY\;nO>'z6 a{hV^bn͟r[~/@{ghh?d[V|zQX0S/&[̧׾v tkzW'NlNYhUU\աebgrR"Z!NpvY7`GЯ+WZr-L&>@/zZb$`Bpx^,:+

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