Where is the local variable distributed? Heap or stack?

http://www-ee.eng.hawaii.edu/~tep/EE160/Book/chap14/subsection2.1.1.8.html This page says that local variables and passed parameters are allocated on the stack, so I tried:

#include <stdio.h>
#include <stdlib.h>
#define A 2000000
#define B 2

typedef struct {
    int a[A][A];
} st;

void fun(st s){}

void main()
{
    st s;
    //fun(s);
}

After compiling and running, an error message is not reported. But when I de-annotate //fun(s), then SIGSEGV is caught. Can someone say why?

+5
source share
2 answers

Where is the local variable distributed? Heap or stack?

On this page local variables are indicated and the passed parameters are allocated on the stack

That's right.

But when I de-annotate // fun (s), then SIGSEGV is caught. Can someone say why?

, №. 2000000x2000000 . , , , .

, , . , , , , s, . , segfault, . , segmenetation. , , , ( ).

¹ , , slugonamission, 16 , , .

+10

, , :

#include <stdio.h>
#include <stdlib.h>
#define A 2000000
#define B 2

typedef struct {
    int a[A][A];
} st;

void fun(st *s){}

void main()
{
    st s;
    fun(&s);
}

, , 4 . //fun(s) , s ​​ .

+2

All Articles