Home > Interview, Linux, Programming > ust-global


  1. What is the difference between malloc and callloc?
  2. I have a structure where i have sort of variables…i want to allocate  memory for structure variable when i use malloc i face problem that is it won’t allocate memory. How can i resolve this scenario?
  3. How to find a linked list is circular or not? Any specific algorith?
  4. About IPC mechanism in linux?
  5. About semaphore, pipe, mutex?
  6. Situation: How to resolve a dead lock in semaphore. How can i give priority to the thread.
  7. About monitor.
  8. What is memset?


  1. Though calloc allocates memory in the form of blocks and malloc in a single block , do they both allocate memory continuously and if there is an obstacle , would callocbe able to jump the obstacle then allocate another block in remaining heap memory. 1)malloc is dynamic memory allocation it allocates the memory and initialize garbage value.
    • calloc
      • Similar to malloc but only difference is initialize zero
      • calculate the memory space
      • take two argument i.e(calloc(no.of.var, size of each var) and allocate block of memory.
      • calloc allocates memory which may/may not be contiguous.
      • calloc Allocates space for an array of elements initializes them to zero and returns a pointer to the memory.
      • But one needs to free the memory explicitly while variables are created using calloc
    • malloc
      • create the memory space
      • Take one argument i.e(malloc(sizeof(int)*10) and allocate bytes of memory.
      • malloc allocates memory as a single contiguous block.
      • if a single contiguous block cannot be allocated then malloc would fail.
      • No need to free the memory explicitly while using malloc. Variables used with malloc are destroyed automatically.
      • it follows from point 2 that calloc will not fail if memory can be allocated in non-contiguous blocks when a single contiguous block cannot be allocated.
      • malloc Allocates memory requests size of bytes and returns a pointer to the Ist byte of allocated space.

Categories: Interview, Linux, Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: