Back to Browse

Accessing Elements of vector using operator [] and at().

360 views
Sep 6, 2023
8:05

This video lecture explains the "difference between using operator [] and at() to access vector elements in C++". It explains accessing elements when the index is within valid range and also explains the case when the index is out of range. It covers exception handing in C++. It uses onlinegdb to demonstrate. std::vector::at reference at (size_type n); Access element Returns a reference to the element at position n in the vector. The function automatically checks whether n is within the bounds of valid elements in the vector, throwing an out_of_range exception if it is not (i.e., if n is greater than, or equal to, its size). This is in contrast with member operator[], that does not check against bounds. https://cplusplus.com/reference/vector/vector/operator%5b%5d/ https://cplusplus.com/reference/vector/vector/at/ Program can be accessed using the below link. https://onlinegdb.com/tTyG2H675 #cppprogramming #cpp #vector

Download

1 formats

Video Formats

360pmp412.0 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Accessing Elements of vector using operator [] and at(). | NatokHD