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…

C Ques & Ans

What does static variable mean ? Static variables are the variables which retain their values between the function call initialized only once their scope is within the function in which they are defined. What is a pointer ? Pointers are variables which stores the address of another variable. That variable may scalar (including another pointer), or an aggregate (array or structure). The pointed-to ob may be part of a larger object, such as a field of a structure or an element in an array. What is a structure ? Structure constitutes a super data type which represents several different data types unit. A structure can be initialized if it is static or global. What are the differences between structures and arrays ? Structure is a collection of heterogeneous data type but array is a collection of homo data types. Array Structure 1-It is a collection of data items of same data type. 2-It has declaration only 3-.There is no keyword. 4- array name represent the address of the starting element. 1-It…