Monday, November 29, 2021

2D Array

 What is 2D Array ?

A 2D array is actually a 1-D array in which each element is itself a 1-D array


#include<stdio.h>
int main() {
    int arr[3][4] = {
      {11, 12, 13, 14},
      {15, 16, 17, 18},
      {19, 20, 21, 22}
    };
    
    int (*ptr)[4] = arr;
    
    for(int i = 0; i<=2; i++) {
        printf("Address of i block of arr %p\n", ptr + i);
        for(int j = 0; j<=3; j++) {
            printf("arr[%d][%d] = %d\n",i,j,*(*(ptr + i) + j) );
        }
    }
    return 0;
}

No comments:

Post a Comment

Priority queue deleting elements after ascending inputs Gaand Fadd

 using namespace std; #include<iostream> #define N 5 class pq { public:     int* arr;     int front;     int rear;     pq() {         ...