#include using namespace std; int main(){ int twoDArray[3][2]; // 3 rows 2 columns twoDArray[0][0] = 11; twoDArray[0][1] = 22; twoDArray[1][0] = 33; twoDArray[1][1] = 44; twoDArray[2][0] = 55; twoDArray[2][1] = 66; cout << "-- 2d array using rows and columns --" << endl; for(int row = 0; row < 3; row++){ for(int col = 0; col < 2; col++){ cout << "twoDArray[" << row << "][" << col << "]:" << twoDArray[row][col] << endl; } } cout << endl; cout << "-- 2d array using pointer --" << endl; int *ptr = &twoDArray[0][0]; for(int i = 0; i < 6; i++){ cout << "twoDArray[" << i << "]:" << *ptr << endl; ptr++; } cout << endl; cout << "-- using dynamic array --" << endl; int arraySize = 4; int *newArray = new int[arraySize]; // attempt to allocate memory if(newArray != nullptr){ // successful memory allocation for(int i = 0; i < arraySize; i++){ newArray[i] = i; } } else { arraySize = 0; // fail to allocate } for(int i = 0; i < arraySize; i++){ cout << "newArray[" << i << "]: " << newArray[i] << endl; } delete[] newArray; // return memory newArray = nullptr; // set to null to be safe return 0; }