Hi I have this question: Why when I\'m allocating memory with malloc for a float array, it allocate more space that i\'m requesting? For example in this code i\'m trying to
You can only get a segmentation fault if a read or write falls in the wrong page. A page is typically 4KiB.
The malloc()
system call may reserve a bit more space than requested, and it reserves a few words of memory before the block for book-keeping, but that your program does not get killed when accessing fk_array[15]
does not mean that it did not access outside the block reserved for it. It probably did, the OS just didn't notice it. If you had allocated another array after allocating fk_array
, you would have had a chance to notice that it was changing.