How to read and write data in 2-D array?

Fill In The Blank
Views 534

Answer:


#include <stdio.h>

int main()
{
    int a[3][2];
    int i, j;

    // Writing data into 2-D array
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 2; j++) {
            a[i][j] = 2;
        }
    }

    // Reading and printing values
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 2; j++) {
            printf("Value in array: %d\n", a[i][j]);
        }
    }

    // Printing value and address
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 2; j++) {
            printf("Value: %d, Address: %p\n", a[i][j], (void*)&a[i][j]);
        }
    }

    return 0;
}


Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Data Structure, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.