M K Q 2023-09-28 14:07 采纳率: 44.4%
浏览 3

c语言简简单单的问题

下面虚线内的程序有几处错误

#include<stdio.h>
int main() {
int m = 10;
const int n = 20;
/*---------------------------------------------------------------------------*/
const int *ptr1 = &m;
int * const ptr2 = &m;
*ptr1 = 3;
ptr2 = &n;
int *ptr3 = &n;
const int * ptr4 = &n;
int * const ptr5;
ptr5 = &m;
const int * const ptr6 = &m;
*ptr6 = 5;
ptr6 = &n;
const int * ptr7;
ptr7 = &m;
/*---------------------------------------------------------------------------*/
return 0

求详细解释,刚刚学c。

  • 写回答

2条回答 默认 最新

  • threenewbee 2023-09-28 14:10
    关注

    看编译器提示即可:

    编译错误:main.c: In function ‘main’:
    main.c:8:7: error: assignment of read-only location ‘*ptr1’
     *ptr1 = 3;
           ^
    main.c:9:6: error: assignment of read-only variable ‘ptr2’
     ptr2 = &n;
          ^
    main.c:10:13: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
     int *ptr3 = &n;
                 ^
    main.c:13:6: error: assignment of read-only variable ‘ptr5’
     ptr5 = &m;
          ^
    main.c:15:7: error: assignment of read-only location ‘*ptr6’
     *ptr6 = 5;
           ^
    main.c:16:6: error: assignment of read-only variable ‘ptr6’
     ptr6 = &n;
          ^
    main.c:20:1: error: expected ‘;’ at end of input
     return 0
     ^~~~~~
    main.c:20:1: error: expected declaration or statement at end of input
    
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 9月28日

悬赏问题

  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络