Select chapter



functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
linked lists (3.papers)
trees (1.papers)
basics (5.papers)
Hide

Sponsored Links


  

c pointers interview questions and answers

1
Is it possible to store 5 ints in this below data structure?

int *p = malloc(5); 
  1. yes
  2. no, you can store only 5 bytes in it, each int is 4 byte, so max u can store 1 integer in it.
  3. it is machine dependent.
  4. it gives compile time error, it is wrong way of initializing a int pointer.
Show Answer
Share Facebook gmail Twitter
2
Will free() function frees the memory immediately in c language?
  1. Yes, immediately that memory will be freed and added to free block of memory segments.
  2. There is no guarantee that it will be freed immediately, until it is not freed that data in that memory will be left intact.
  3. none of the above two statements are true.
  4. Question is wrong
Show Answer
Share Facebook gmail Twitter
3
after freeing a pointer in c, will free function initializes that pointer to NULL?
  1. No, it is programmers' duty to assign it with NULL.
  2. it will always initialized to NULL after freeing.
  3. some times it makes it NULL and some times not.
  4. that pointer will not be initialized to NULL, until that memory block is really freed by system.
Show Answer
Share Facebook gmail Twitter
4
What is a dangling pointer in c?
  1. A pointer which is allocated some memory, and forgot to free it.
  2. A pointer holding some address of a memory block, which already went out of scope or which is already freed.
  3. A pointer assigned with NULL.
  4. None of the above
Show Answer
Share Facebook gmail Twitter
5
What is a memory leak in c?
  1. A pointer which is allocated some memory, and forgot to free it.
  2. A pointer holding some address of a memory block, which already went out of scope or which is already freed.
  3. A pointer assigned with NULL & freed.
  4. None of the above
Show Answer
Share Facebook gmail Twitter
6
If sizeof operator is used on a pointer in c, will it tell the size of memory block allocated to it?
  1. sizeof is compile time operator.
  2. memory allocated to pointers happen at run time, so with option 1 and option 2 it is clear why it is not possible.
  3. Yes, it is quite possible to obtain size of block allocated to a pointer.
  4. Even malloc & free also don't know how much memory block was allocated to a pointer.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
10
will free() function works on the memory(pointer) which was allocated with calloc()?
  1. no, use cfree() instead.
  2. yes, it works with calloc as well.
  3. calloc will free memory automatically on program exit, so no need to use free.
  4. none of the above
Show Answer
Share Facebook gmail Twitter
11
If realloc() method colud find the new memory space, in the same contiguous block where old pointer is pointing to, then what does realloc() method return?
  1. It will allocate extra memory which is contiguous to original one, and returns same old pointer.
  2. null pointer
  3. still it creates a new memory block and returns newly allocated pointer.
  4. can't predict.
Show Answer
Share Facebook gmail Twitter
12
If realloc() method couldn't able to allocate new memory space, then what will happen to the previous memory block which was passed to realloc() method? Will it be usable or un usable?
  1. It is rare case, in such case your memory will become unusable.
  2. In that case, your previous memory block will not be disturbed, so you can use it as usual.
  3. we can't predict its behavior.
  4. it might crash.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
14
What happens if memory is not freed which was allocated previously by malloc or calloc? Will it stay for ever with out being freed?
  1. A real good OS will take care of memory leaks after that program has stopped. OS has to reclaim resources allocated to it.
  2. Yes, it will be left for ever and it simply consumes that memory until you switch off your machine.
  3. C has automatic garbage collection, so don't need to worry about freeing a memory block.
  4. All above options are true.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
16
In c will the malloc() function allocates memory immediately after calling it, or it will postpone memory allocating until that memory is really used ?
  1. It will allocate memory immediately.
  2. It will differ it to later point of time, till when the program actually uses that memory.
  3. It is implementation dependent, though most of the systems implement in option 1 way, there are some systems which will do lazy initialization of that malloced object.
Show Answer
Share Facebook gmail Twitter
17
In the segmented memory architecture like DOS, how much maximum memory can be allocated using malloc() method?
  1. 640KB
  2. 640 MB.
  3. You can allocate as much memory as possible it is free and available.
  4. can't say.
Show Answer
Share Facebook gmail Twitter
18
If I want lot of small chunks of memory areas dynamically, then there is a chance that in the middle of the program my application may run out of memory if others start using the memory. How to avoid this?
  1. If ram is really going low, then OS should probably clean the memory using some paging concept.
  2. Allocate complete memory at initially, and keep un used blocks in your own free list so that you don't need to depend on OS memory allocation.
  3. Option 2 has to be used carefully, as your program might be unnecessarily blocking memory from other programs. So one has to use it efficiently.
  4. can't say.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :