retagged by
899 views
1 votes
1 votes

Q. Assume the following C variable declaration

int * M[10], N[10][10];

of the following expressions.

1. M [2][4]

2. N [2]

3. M [3]

4. N [2][4]

Which will not give compile time errors if used as left-hand sides of assignment statements in a C program?

(a) 2 and 4 only                                                           (b) 2, 3 and 4 only

(c) 4 only                                                                     (d) 1, 3 and 4 only

retagged by

2 Answers

2 votes
2 votes
I think answer is D

 

Int *M[10];

Since m is array which is basically pointer array.

So M[2][4] is also valid.

 

And N is two dimensional array so

i think N[2] will give compile time error.
edited by
2 votes
2 votes
In C, while using multi dimensional arrays the parameter declaration must include the all other dimensions except the first dimension. Specifying the first dimension i.e. the number of rows is optional.
Here, M is an array of 10 pointers. The definition of M however only allocates 10 pointers and does not initialize them; initialization must be done explicitly, either statically or with code. So M[3] and M[2][4] both are valid as the latter refers  the data to which the pointer points to.
N[2][4] is clearly valid as N is a true 2-dimensional array.
But N[2] is invalid as we are not specifying the relevant 2nd dimension here and hence the compiler will give an error.
So, D is the answer.

Related questions

13 votes
13 votes
8 answers
1
Na462 asked Aug 22, 2018
5,469 views
Consider a 2 dimensional array A[40...95,40...95] in lower triangular matrix representation. The size of each element of array is 1 Byte.If array is implemented in memory...
1 votes
1 votes
1 answer
2
Mrityudoot asked Feb 2
246 views
In what cases does an uninitialized array have values = 0 and for which cases does it have values = garbage values. How to differentiate?
1 votes
1 votes
1 answer
3
Mrityudoot asked Feb 2
131 views
Does C support fractional Indices?float x = some fraction;Is float a[x] valid declaration?
1 votes
1 votes
1 answer
4
amitarp818 asked Oct 25, 2023
408 views
How is the address written for 3-dimensional arrays?In some answers, I saw (row, column, frame) and in others, it was (frame, row, column) Which one to follow??Also, how ...