Exception thrown at 0x00007FF795014E96 in Project1.exe: 0xC0000005: Access violation writing location 0x00000000705B49C0

2
#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);
}

I want to send a variable to function from main, this code is not working on visual studio but this works on dev-c++. I want to work on visual studio, what is the problem?

c
arrays
malloc
asked on Stack Overflow Apr 20, 2019 by Hacktan • edited Apr 20, 2019 by Hacktan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0