main.c: In function 'main': main.c:8:9: error: assignment of read-only location '*str' str[0] ='p'; //will return error ^ Here, the statement str[0]='p' will try to change the first character of the string, thus, the "Error: assignment of read-only location" will occur....
编译结果: main.c: In function 'main':main.c10: error: assignment of read-only location '*ptr' *ptr = 1; ^main.c9: error: assignment of read-only variable 'ptr' ptr = &var2; ^ 7 指针与函数 7.1 函数指针 指针与函数相结合有两种情况:指针函数、函数指针。 指针函数,它的本质是一个函数...
以上代码显示了错误:"assignment of read-only location '*ptr'"。这个错误意味着我们不能改变指针所指向的变量的值。 常量指针指向常量 常量指针指向常量是指上述两种指针的组合。它既不能改变所指变量的地址,也不能改变该地址处的值。 语法 const <指针类型> * con...
c:7:10: error: assignment of read-only location '*ptr' *ptr = 1; ^ 编译报错也很明显: *ptr是一个只读的。所以不能通过ptr来修改var1的值。 但是,我们可以将ptr指向其他的变量: #include<stdio.h> int main(void) { int var1 = 0; const int* ptr = &var1; printf("%d\n", *ptr);...
prog.c: In function 'main': prog.c:6:3: error: assignment of read-only variable 'a' a=100; ^ How to fix it? Assign value to the variable while declaring the constant and do not reassign the variable. Correct Code #include<stdio.h>intmain(void){constinta=100;printf("a=%d\n",...
test1.c:6: error: assignment of read-only location ‘*A’ 改下源代码: [rocrocket@wupengchong const_test]$ cat test1.c #include<stdio.h> intmain() { intnum=12; inttmp=100; intconst*constA=# A=&tmp; printf("result=%d\n",*A); ...
尝试修改指针p指向的值,编译后报错:[Error] assignment of read-only location '*p',p指向的位置为只读。 修改一下a的值,看运行结果。 没有报错,a的值被成功修改。 再试一下,修改p的值: inta = 2; intb = 10; constint*p = &a; printf("%x %d\n",p,*p); ...
C语言程序设计(第4版)》-CodeBlocks常见编程错误英汉对照-051 2.1.2.5 Code::Blocks常见编译错误和警告信息的英汉对照 Code::Blocks常见编译错误和警告信息的英汉对照如表2-1所示。
十二、assignment of read-only variable 'xxx' 给const赋值了,比如: const int a=2; a=3; //a是常量,不能被赋值 十三、uninitialized const 'xxx' 没初始化,注意对常量定义时应当顺带初始化,比如: const int a; //没初始化 const int a=0; //改正后 十四、no matching function for call to 'fu...
("*p1 = %d, p1 = %p, &val_2 = %p\n",*p1,p1,&val_2);#endif#ifPOINTER_TO_CONST/* 对于指向常量的指针p2来说,不可以通过指针直接修改指向内存的值,可以将指针指向另一个内存 */// 不可以通过p2直接修改指向内存的值,error: assignment of read-only location ‘*p2’// *p2 = 12;// ...