It looks like the system allocates maximum memory space
Yes, but this is not really a problem in this case. The array you declare is local and automatic, so it will most likely be allocated on the stack. The stack size is limited, even more limited than dynamically allocated memory (usually a lot) and with a small megabyte of large size (if I remember correctly, this is actually 1 MB on Windows by default), it quickly collides with other memory areas.
If you do not want this, declare your variable as a variable file-scope ("global") or as static (read about side effects).
In addition, you are right that the OS also limits all memory - it tries to maintain democracy between processes. Even if you run the program on a server with 128 gigabytes of RAM, malloc() will most likely fail, for example, if you want to allocate 32 gigabytes. Such memory is not needed at all, and the OS protects other processes from a single erroneous (or intentional) supply of resources.
user529758
source share