Pr.Pg Next Pg

C Programming Interview Questions and Answers Part 5

 

41.What is storage class? What are the different storage classes in C?

  • Storage class is an attribute that changes the behavior of a variable. It controls the lifetime,scope and linkage.

  • The storage classes in c are auto, register, and extern, static, typedef.

 

42.What the advantages of using Unions?

  • When the C compiler is allocating memory for unions it will always reserve enough room for the largest member.

 

43.What is the difference between Strings and Arrays?

  • String is a sequence of characters ending with NULL .it can be treated as a one dimensional array of characters terminated by a NULL character.

 

44.What is a huge pointer?

  • Huge pointer is 32bit long containing segment address and offset address.

  • Huge pointers are normalized pointers so for any given memory address there is only one possible huge address segment : offset pair.

  • Huge pointer arithmetic is doe with calls to special subroutines so its arithmetic slower than any other pointers.

 

45.In C, why is the void pointer useful? When would you use it?

  • The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.

 

46.What is generic pointer in C?

  • In C void* acts as a generic pointer.

  • When other pointer types are assigned to generic pointer,conversions are applied automatically (implicit conversion).

47.How pointer variables are initialized?

  • Pointer variables are initialized by one of the following ways.

  • Static memory allocation

  • Dynamic memory allocation

 

48.What are the advantages of auto variables

  • The same auto variable name can be used in different blocks.

  • There is no side effect by changing the values in the blocks.

  • The memory is economically used.

  • Auto variables have inlierent protection because of local scope.

 

49.What is dynamic memory allocation?

  • A dynamic memory allocation uses functions such as malloc() or calloc() to get memory dynamically.

  • If these functions are used to get memory dynamically and the values returned by these function are assigned to pointer variables, such a way of allocating memory at run time is known as dynamic memory allocation.

 

50.What is the purpose of realloc?

  • It increases or decreases the size of dynamically allocated array.

  • The function realloc (ptr,n) uses two arguments. The first argument ptr is a pointer to a block of memory for which the size is to be altered. The second argument specifies the new size.

  • The size may be increased or decreased. If sufficient space is not available to the old region the function may create a new region.

Pr.Pg border                                              Next Pg