C++ Deque operator[]()C++ Deque operator[] function is used to access the element at specified position pos. If position pos is greater than the size of container then it returns a value 0. Difference between operator[]() & at()When position pos is greater than the size of the container then operator[]() function returns a value 0 while at() function throws an exception i.e out of range. SyntaxParameterpos: It defines the position of an element which is to be accessed. Return valueIt returns a reference to an element at position pos in the deque container. Example 1Let's see a simple example Output: mango is my favorite fruit In this example, operator[]() function access each element of deque a. Example 2Let's see a simple example when pos is out of range. Output: 0 In this example, operator[]() function tries to access the position which is greater than the size of the container. Therefore, it returns 0. Next TopicC++ Deque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India