MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Consider the following declaration of a two-dimensional array in C:char a[100][100]Assuming that the main memory is byte-addressable and that array is stored starting form memory address 0, the address of a [40] [50] is
A
4050
B
4040
C
5050
D
5040
Explanation: 

Detailed explanation-1: -Consider the following declaration of a two-dimensional array in C: char a [ 100 ] [ 100 ]; Assuming that the main memory is byte-addressable and that the array is stored starting from memory address, the address of a [ 40 ] [ 50 ] is: 4040.

Detailed explanation-2: -A 2D array is stored in the computer’s memory one row following another. The address of the first byte of memory is considered as the memory location of the entire 2D array.

Detailed explanation-3: -Like the one-dimensional arrays, two-dimensional arrays may be initialized by following their declaration with a list of initial values enclosed in braces. Ex: int a[2][3]=0, 0, 0, 1, 1, 1; initializes the elements of the first row to zero and the second row to one. The initialization is done row by row.

Detailed explanation-4: -To declare a two-dimensional array using both dimensions, we just have to pass the number of rows and the number of columns of the matrix in the square brackets as shown below: int[][] a = new int[2][2];

There is 1 question to complete.