i mean if a problem needs to scan 10^6 integer values.how am i supposed to store them ?if i declare array of size 10^6 i’m getting error.please help me with this.thanks in advance
Store the array outside main() because if the array is stored inside main(), the stack memory is used up. Stack memory is usually limited by the user.
When the array is stored outside main(), data will get mapped to either Data Segment or BSS.
You can see the memory layout in gcc using:
->gcc memory-layout.c -o memory-layout
Check these out:
This is incorrect. Global (or static) variables in C are stored in the data segment or BSS segement, not in the heap! The heap must be manually allocated and freed.
You can create an array of size 10^6. that wont lead to any error but if u are using more memory during the process , that might lead to segmentation fault.
In situations where we MUST read all the 10^6 integers , we have to take care of the memory usage of our program and try to reduce it accordingly.