Multidimensional arrays are arrays that have multiple dimensions or levels. These are commonly used in scientific and mathematical applications where multiple sets of data need to be stored and manipulated.
Example:
int arr2D[3][4];
This creates a 2D array with 3 rows and 4 columns. Each element in the array can be accessed using 2 indices, the first index specifies the row and the second index specifies the column.
int arr3D[3][4][5];
This creates a 3D array with 3 rows, 4 columns, and 5 levels. Each element in the array can be accessed using 3 indices, the first index specifies the row, the second index specifies the column, and the third index specifies the level.
Package library: Standard Template Library (STL)
2. Dynamic Arrays
Dynamic arrays are arrays that can change size at runtime. This is useful when the size of the array is unknown or changes frequently.
Example:
int *arr = new int[10];
This creates a dynamic array with 10 elements. The size of the array can be changed later using the "new" operator.
int *arr = new int[10]; delete[] arr; arr = new int[20];
This creates a dynamic array with 10 elements, deletes it, and then creates a new dynamic array with 20 elements.
Package library: Standard Template Library (STL)
3. Vectors
Vectors are dynamic arrays that are part of the Standard Template Library (STL). They are similar to dynamic arrays but have additional features such as automatic resizing and built-in functions for adding, removing, and accessing elements.
Example:
vector v;
This creates an empty vector of integers. Elements can be added using the "push_back" function.
This adds 3 elements to the vector with the values 10, 20, and 30.
Package library: Standard Template Library (STL)
4. Arrays of Pointers
Arrays of pointers are arrays where each element is a pointer to another variable. This is useful when working with complex data structures or when passing arrays as function arguments.
Example:
int *arr[10];
This creates an array of 10 pointers to integers. Each element in the array can be set to point to a different integer variable.
int a = 10; int b = 20; arr[0] = &a; arr[1] = &b;
This sets the first element of the array to point to the integer variable "a" and the second element to point to the integer variable "b".
Package library: Standard Template Library (STL)
C++ (Cpp) array::dims - 25 examples found. These are the top rated real world C++ (Cpp) examples of array::dims from package PDAL extracted from open source projects. You can rate examples to help us improve the quality of examples.