Thread: C 2D arrays
View Single Post
  #1   (View Single Post)  
Old 1st August 2008
jgroch jgroch is offline
Port Guard
 
Join Date: Jul 2008
Posts: 14
Default C 2D arrays

I'm trying to learn C and I'm a little embarrassed to ask, but I've spent more time trying to find an answer than I think should be necessary without finding out why, so I'll ask.

Why does the following create a segmentation fault when run?

Code:
int main() {
	int a[1000000][1000000];
	a[0][0] = 0;
}
As I understand it, seg faults mean I'm trying to access areas of memory that I shouldn't. So I'm guessing I'm not initializing an array properly. Or is it something to do with dimensions being to large?

Any help would be appreciated.
Reply With Quote