2014-02-06 143 views
-1

Got xCode 5.0.2昨天买了mac,不明白为什么这个简单的代码不起作用。简单的代码不起作用。不知道为什么

#include "stdio.h" 

int main(){ 
    int N; 
    printf("vvedite koli4estvo dannih\n");//mistake and warning is here 
    scanf("%d", &N); 
    int *arr = new (int [N]); 

    return 0; 
} 

错误是

expected expression 

implicit declaration of function 'new' is invalid in c99 
+0

这是'main.m'文件吗?改为'main.mm' – Wain

+0

试试这个'int arr [N];' – BLUEPIXY

+0

尝试int arr [N]也出错 –

回答

3

你的代码是用C写的,但使用的是new;一个C++运算符。改为使用malloc

int *arr = malloc(sizeof(int)*N); // allocates memory for N itegers 
+0

难道你不知道我该如何让我的xCode读取C++以及c?因为在MSDN上的第一个代码读取得很好 –

+0

几乎所有的ansi C代码都在C++编译器上运行。 – haccks

相关问题