| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2526 人关注过本帖
标题:请教诸神~ const用在二维数组上为什么会出现这种情况?
取消只看楼主 加入收藏
rupei110
Rank: 1
等 级:新手上路
帖 子:26
专家分:3
注 册:2010-11-15
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:3 
请教诸神~ const用在二维数组上为什么会出现这种情况?
#include <stdio.h>

void display(const int r[2][2]);

int
main()
{
    int i,j;
    int r[2][2];

    for (i = 0; i < 2; ++i)
        for (j = 0; j < 2; ++j)
            scanf("%d", &r[i][j]);

    display(r);
    printf("\n");
    return(0);
}
void
display(const int r[2][2])
{
    int i,j;
    for(i = 0; i < 2; ++i)
        for (j = 0; j < 2; ++j)
            printf("%d ", r[i][j]);
}
运行~出现:
a.c: In function ‘main’:
a.c:15: warning: passing argument 1 of ‘display’ from incompatible pointer type
a.c:3: note: expected ‘const int (*)[2]’ but argument is of type ‘int (*)[2]’
为什么~这是 什么意思?
搜索更多相关主题的帖子: const 
2010-11-17 03:16
rupei110
Rank: 1
等 级:新手上路
帖 子:26
专家分:3
注 册:2010-11-15
收藏
得分:0 
回复 2楼 韭菜
ubuntu下的gcc编译器。。。
2010-11-17 12:06
rupei110
Rank: 1
等 级:新手上路
帖 子:26
专家分:3
注 册:2010-11-15
收藏
得分:0 
回复 4楼 xiaomarn
当为一维数组时就不会报错 gcc编译器~
2010-11-17 12:12
rupei110
Rank: 1
等 级:新手上路
帖 子:26
专家分:3
注 册:2010-11-15
收藏
得分:0 
回复 5楼 forever74
当我换位如此写法~
a.c:3: error: ‘type name’ declared as function returning an array
a.c: In function ‘main’:
a.c:15: warning: passing argument 1 of ‘display’ from incompatible pointer type
a.c:3: note: expected ‘int (*)(const int *)’ but argument is of type ‘int (*)[2]’
a.c: At top level:
a.c:21: error: ‘type name’ declared as function returning an array
a.c: In function ‘display’:
a.c:21: error: parameter name omitted
a.c:26: error: ‘r’ undeclared (first use in this function)
a.c:26: error: (Each undeclared identifier is reported only once
a.c:26: error: for each function it appears in.)
是编译器的问题吗?2L貌似运行成功
2010-11-17 12:20
快速回复:请教诸神~ const用在二维数组上为什么会出现这种情况?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015844 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved