C programming, why does this large array declaration produce a segmentation fault?

Posted by noneme on Stack Overflow See other posts from Stack Overflow or by noneme
Published on 2010-06-16T00:06:05Z Indexed on 2010/06/16 0:12 UTC
Read the original article Hit count: 132

Filed under:
|
|

This code produces a segmentation fault during the array declaration. I'm confused as to why this happens. I intentionally selected 2000000000 as a value because it is below 2^31 and can fit into an integer variable.

int main()
{

    int  nums_size = 2000000000;

    int nums[nums_size];

    int i;
    for(i = 0; i < nums_size; i++) {
        nums[i] = i;
    }


    return 0;

}

© Stack Overflow or respective owner

Related posts about c

    Related posts about arrays