注册 登录
编程论坛 C语言论坛

以下两份代码为何有这区别?

hffjhhh 发布于 2020-06-19 22:19, 2230 次点击
第一份代码可以将指针a指向数组首地址b,代码如下:
程序代码:
#include"stdio.h"
int main(void){
    char *a;
    char b[100];
    a=b;
    return 0;
}

而第二份代码却无法将数组首地址a指向指针b,这是为什么?代码如下:
程序代码:
#include"stdio.h"
int main(void){
    char a[100];
    char *b;
    a=b;
    return 0;
}
5 回复
#2
fulltimelink2020-06-20 07:43
Objects of array type are not modifiable lvalues, and although their address may be taken, they cannot appear on the left hand side of an assignment operator.
https://en.
#3
吹水佬2020-06-20 08:09
    char *b;
    a=b; b是什么?
#4
hffjhhh2020-06-20 13:05
以下是引用吹水佬在2020-6-20 08:09:48的发言:

    char *b;
    a=b; b是什么?

b是指针.
#5
hbccc2020-06-20 20:05
b没有赋值啊,就算赋值了,也只是把b给了a,结果a也丢了
#6
ditg2020-06-21 00:01
编个小程序,看懂调试信息,至少比瞎猜更有意义
1