Languages-C & C Plus Plus [TCS Placement]: Sample Questions 72 - 73 of 119

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 72

C & C Plus Plus



Why reference is not same as a pointer?


Choice (4)


A reference can never be null.


Reference doesn՚t need an explicit dereferencing mechanism.


A reference once established cannot be changed.


All a., b. and c. are correct




  • Both references and pointers can be used to change local variables of one function inside another function.
  • Both of them can also be used to save copying of big objects when passed as arguments to functions or returned from functions, to gain efficiency.
  • References do not provide physical memory address to the programmer. They are handled by the compiler. They can never be null.
  • A reference is statically associated with one memory location (or variable) they cannot be changed.
  • Reference does not need an explicit dereferencing mechanism (dereferencing is handled by the compiler) . A reference has the same memory address as the item it references.
  • A pointer is a variable that holds a memory address.
  • Const references can be bound to temporaries.
Given the Image is Define the Difference between References and Pointers

Question 73

C & C Plus Plus

Describe in Detail


What is the difference between calloc () and malloc () ?


  • calloc (…) allocates a block of memory for an array of elements of a certain size. By default the block is initialized to 0. The total number of memory allocated will be (number_of_elements ⚹ size) .
  • malloc (…) takes in only a single argument which is the memory required in bytes. malloc (…) allocated bytes of memory and not blocks of memory like calloc (…) .
  • malloc (…) allocates memory blocks and returns a void pointer to the allocated space, or NULL if there is insufficient memory.
  • calloc (…) allocates an array in memory with elements initialized to 0 and returns a pointer to the allocated space. calloc (…) calls malloc (…) in order to use the C ++ _set_new_mode function to set the new handler mode.
Given the Image is Define the Difference between Calloc () and Malloc ()

Developed by: