在Project1.exe中的0x00007FF795014E96处引发异常:0xC0000005:访问冲突写入位置0x00000000705B49C0

时间:2019-04-20 10:23:30

标签: c arrays malloc

#include <stdio.h>
#include <ctype.h>
void spyral(int boyut)
{
    int i;
    int*a = malloc(boyut * sizeof(int*));
    for (i = 0; i < boyut; i++)
    {
        a[i] = i + 1; //program is erroring here
    }
    for (i = 0; i < boyut; i++)
    {
        printf("%d", a[i]);
    }
    /*int x = 5;
    int y = 5;
    int** a = malloc(x * sizeof(int*));
    for (int i = 0; i < y; i++) {
        a[i] = malloc(sizeof(int*) * y);
    }*/
}
int main()
{
    spyral(6);
}

我想从main发送一个变量到函数,此代码在Visual Studio上不起作用,但在dev-c ++上起作用。我想在Visual Studio上工作,这是什么问题?

0 个答案:

没有答案