Tuesday, April 6, 2010

Some interview questions with answers

  1. Usage of pointers and their fundamentals in C?
    Pointers are mainly used for the dynamic allocation of memory. A pointer contains the address of the variable. They are also helpful in passing parameters to subroutines.
     void* sample;
    Using the above example’s definition and assigning the pointer to void to the address of an integer variable is perfectly correct.
    sample=&i; where i is an int.
    Using the above example to define the pointer to void and assign the pointer to void to the address of a float variable as below is also perfectly correct.
    sample=&f; where f is a float
    Pointer to void, or a void pointer, is a special type of pointer that has a great facility of pointing to any data type.NULL pointer is a type of pointer of any data type and generally takes a value as zero. This is, however, not mandatory. This denotes that NULL pointer does not point to any valid memory address. It is important to note that a NULL pointer is different from a pointer that is not initialized.

  2. What is the difference between structures and unions in C?
    Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.
    Structure enables us treat a number of different variables stored at different in memory.
    Since all of them are referring to the same location in memory the modification of one of the elements will affect the value of all of them. We cannot store different values in them independent from each other.
  3. Basic concepts about data structures like trees, linked lists, circular lists, queues, arrays?
    The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations.

No comments:

Post a Comment