Skip to main content


Recent posts

Sherlock Holmes

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…

C Ques & Ans page 2

What is a far pointer ? Where we use it ? In large data model (compact, large, huge) the address B0008000 is acceptable because in these model all pointers to data are 32bits long. If we use small data model(tiny, small, medium) the above address won’t work since in these model each pointer is 16bits long. If we are working in a small data model and want to access the address B0008000 then we use far pointer. Far pointer is always treated as a 32bit pointer and contains a segment address and offset address both of 16bits each. Thus the address is represented using segment : offset format B000h:8000h. For any given memory address there are many possible far address segment : offset pair. The segment register contains the address where the segment begins and offset register contains the offset of data/code from where segment begins. What is a NULL Pointer ? Whether it is same as an uninitialized pointer ? Null pointer is a pointer which points to nothing but uninitialized pointer may point…