Skip to main content

Popular posts from this blog

C Ques & Ans page 3

How can you increase the size of a dynamically allocated array ? /* Allocate space for an array with ten elements of type int. */  int *ptr = malloc(10 * sizeof (int));  if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */ realloc It is often useful to be able to grow or shrink a block of memory. This can be done usingrealloc which returns a pointer to a memory region of the specified size, which contains the same data as the old region pointed to by ptr (truncated to the minimum of the old and new sizes). If realloc is unable to resize the memory region in-place, it allocates new storage, copies the required data, and frees the old pointer. If this allocation fails, realloc maintains the original pointer unaltered, and returns the null pointer value. The newly allocated region of memory is uninitialized (its contents are not predictable). The function prototype is  void *realloc(void *pointer, size_t size); When reallocating memor…

Story Books of Rabindranath Thakur