1.

What is the difference between begin() and cbegin() in vectors?(a) both are same(b) begin() returns iterator to first element and cbegin() returns iterator to last element(c) begin() returns an iterator to first element whereas cbegin() returns constant iterator to first element(d) begin() returns returns first element cbegin() returns voidI have been asked this question by my college professor while I was bunking the class.My query is from seq_con Vector Class in division Class Hierarchies, Library & Containers of C++

Answer»

Correct choice is (c) begin() returns an ITERATOR to first element whereas cbegin() returns constant iterator to first element

The best I can explain: Both begin() and cbegin() are used to ACCESS the first element of the VECTOR. The function begin() returns an iterator to first element whereas cbegin() returns a constant iterator to first element.



Discussion

No Comment Found

Related InterviewSolutions