An array in a memory-limited system

Please note that my system has memory, but it is scattered in different places (fragmented). There are no free areas of free memory. In this case, if I declare a character array of size 10 in C, what will happen?

+3
source share
2 answers

If "my system has memory, but it is scattered in different places (fragmented)" means that the heap virtual memory is fragmented and "declare a character array of size 10" means that you create an array of characters of size 10 in the memory stack :

char str[10];

then the array will be created successfully.

" 10" , malloc() ( ):

char *str2;
str2 = (char*) malloc(10 * sizeof(char));

malloc() NULL.

+8

, , , ( ), , - - , (, ), .

+2

Source: https://habr.com/ru/post/1784911/


All Articles