Computer Science, asked by KaunHuMai, 5 months ago

Write the output of the following function and also explain why ?

#include
#include
void main()
{
int arr[3][2] = {{2, 1}, { 3, 7}, {8,5}};
clrscr();
printf(“%d\n”,arr[2][0]);
getch();
}

Answers

Answered by Anonymous
5

\red{\underline{ \rm \large \: \: Correct \; program:- }}

#include<stdio.h>

#include<conio.h>

void main()

{

int arr[3][2] = {{2, 1}, { 3, 7}, {8,5}};

clrscr();

printf(“%d\n”,arr[2][0]);

getch();

}

\color{cyan}\underline{ \rm \large \: \: Output:- }

8

\color{lime}\underline{ \rm \large \: \: Let's \; know \; the \; reason:- }

We know that two dimensional arrays provide the way to store data in the form of grid and table

Two - dimensional array are declared as :-

data_type variable_name [row_size] [column_size]

As given in the program :-

int arr[3][2]

Declares arr as two - dimensional array , which contains 3 row and 2 columns and can be shown as follow :

⠀⠀⠀⠀⠀C 0 ⠀⠀⠀⠀C1⠀⠀⠀

R 0⠀| ⠀a[0][0]⠀| ⠀a[0][1]⠀|

R 1⠀| ⠀a [1] [0]⠀| ⠀a[1] [1]⠀|

R 2⠀|⠀a [2][0]⠀| ⠀a[2][2]⠀|

two dimensional array may be initialised by specifying bracketed values for each row .

following you can see the array of three rows and each row has two column :-

int arr[3][2] = {{2, 1}, { 3, 7}, {8,5}};

⠀⠀⠀⠀⠀⠀

|⠀2⠀|⠀1⠀|

|⠀3⠀|⠀7⠀|

|⠀8⠀|⠀5⠀|

Now we can see that

  • [0][0] = 2
  • [1][0] = 3
  • [2][0] = 8
  • [0][1] = 1
  • [1][1] = 7
  • [2][2] = 5

And it is given that printf(“%d\n”,arr[2][0]);

★ [2][0] = 8

Hence proved !

Attachments:

KaunHuMai: thank you
Anonymous: your welcome
Anonymous: why you have reported the answer ?
Similar questions