How it works...
The user will be asked to specify the number of elements. The value entered by the user will be assigned to the variable n. Let's assume the value entered by the user is 4, which is then assigned to the variable n. Using the calloc function, 4 memory blocks are dynamically allocated, where the size of each memory block is equal to the size consumed by an int data type. In other words, a memory block that can store four integer values is dynamically allocated and a pointer, ptr, is set to point to it. If the ptr pointer is NULL, then this means that the memory could not be allocated and the program will terminate after displaying an error message.
If the memory is successfully allocated, the user will be asked to enter four ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access