Javatpoint Logo
Javatpoint Logo

2D Vector in C++ with User Defined Size

This tutorial aims to explain the concept of a 2D vector with a user-defined size. We must be aware of 2d arrays where the array is two-dimensional, which can be visualized as a matrix.

Here the concept of vectors solves the central pain point of fixed-size collections, wherein the idea of vectors is dynamic.

A 2D vector is simply a vector of a vector and is involved in the heart. The time and space complexities of a 2D vector are O(1).

Approach 1:

C++ Code

Approach 2:

C++ code

Output:

11 2 33 
74 5 66 
7 98 9

Approach 3:

C++ code

Output:

1 2 3 4 5 
2 3 4 5 6 
3 4 5 6 7 
4 5 6 7 8

Approach 4:

C++ code

Output:

0 0 0 0 
0 0 0 0 
0 0 0 0






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA