0

The following piece of code compiles and runs without any problems:

#include <stdbool.h>
#define N 1000000

int main( void ){

  bool num[N];
  bool *p;
  for( p = num; p < &num[N]; )
    *p++ = true;
}

If, however, the value of N gets 10 times bigger (extra 0 -- ten million instead of one million),

#include <stdbool.h>
#define N 10000000

int main( void ){

  bool num[N];
  bool *p;
  for( p = num; p < &num[N]; )
    *p++ = true;
}

I get a segmentation fault on the line beginning with for. What is going on here? I don't see anything special about going from 1000000 to 10000000 (million to ten million).

dmitry
  • 304
  • 3
  • 9

0 Answers0