首页 新闻 会员 周边

C/C++类型检查

0
悬赏园豆:5 [待解决问题]
#include<stdio.h>
int main()
{
    int i,n;
    while(1)
    {
        scanf("%d",&n);
        int a[1<<n];
        for(i=0;i<(1<<n);i++)
            scanf("%d",&a[i]);
        for(i=0;i<(1<<n);i++)
            printf("%d ",a[i]);
        printf("\n");
        printf("%d %d\n",a,&a[(1<<n)-1]);
    }
    return 0;
}

 

VC报错:

error C2057: expected constant expression
 : error C2466: cannot allocate an array of constant size 0
 : error C2133: 'a' : unknown size
Error executing cl.exe.

linshi.exe - 3 error(s), 0 warning(s)

codeblock就 能够运行的!

 

C/C++中 scanf("%d",&n); int a[1<<n]; 以上形式的写法对吗? VC6.0报错,但codeblock能够运行,不解?

<<运算符是在编译时检查的吧,那么就是codeblock错误喽,但是听说codeblock兼容C++标准要高于VC的……
桑海的主页 桑海 | 初学一级 | 园豆:197
提问于:2013-01-27 10:14
< >
分享
所有回答(1)
0

VC不支持动态数组。要使用动态分配内存请使用new语句。

CodeBlocks使用的是G++编译器,那个支持最新的C++标准

飞鸟_Asuka | 园豆:209 (菜鸟二级) | 2013-01-27 12:45
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册