Welcome Guest.

3Answers

C language array what is preventing stack overflow

Asked by: Christine 190 views IT March 7, 2019

For example;

#include<stdio.h>

int a[1000000]={0},b[1000000];//Prevent stack overflow 

int main(){

   int n,m,i,j,k=0;

    scanf("% d",&n);

    for(i=n-1;i>=0;i--){

        Scanf("%d",&a[i]);

}

    scanf("%d",&m);

    for(j=0;j<m;j++){

        scanf("%d",&b[j]);

    }

. . . . .

3 Answers

  1. +5Votes  

    C language default does not prevent stack overflow function

    This is implemented by the compiler

    Some compilers have stack check and can also set stack size

    And your program, a is a global variable, it is generally allocated in the static area, independent of the stack

    Thomas Williams- March 7, 2019 |

  2. +4Votes  

    C language array and The stack has a hair relationship

    Timothy- March 7, 2019 |

  3. +4Votes  

    inc returns the address of the first element of the array a, that is, the pointer b is assigned the address of the first element of the array a, also points to the array a, and No new memory is allocated, and a and b point to the same array. If you need to allocate new memory, you can use malloc. b = (u8 *) malloc(8 * sizeof(u8)); // dynamically allocate 8 spaces of size u8

    Sharon Patel- March 7, 2019 |