C | Arrays | Question 6

Assume the following C variable declaration

int *A [10], B[10][10];  

Of the following expressions
I A[2]
II A[2][3]
III B[1]
IV B[2][3]
which will not give compile-time errors if used as left hand sides of assignment statements in a C program (GATE CS 2003)?

(A) I, II, and IV only
(B) II, III, and IV only

(C) II and IV only
(D) IV only


Answer: (A)

Explanation: See following for explanation.

int main() 
{ 
  int *A[10], B[10][10]; 
  int C[] = {12, 11, 13, 14}; 
  
  /* No problem with below statement as A[2] is a pointer 
     and we are assigning a value to pointer */
  A[2] = C;  
  
  /* No problem with below statement also as array style indexing 
      can be done with pointers*/
  A[2][3] = 15; 
  
  /* Simple assignment to an element of a 2D array*/
  B[2][3]  = 15; 
  
  printf("%d %d", A[2][0], A[2][3]); 
  return 0;
}


Quiz of this Question



My Personal Notes arrow_drop_up

Article Tags :
Practice Tags :



Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.