C |数组|问题6

假设变量C声明如下

null

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


下面的表达 I A[2] II A[2][3] III B[1] IV B[2][3] 如果在C程序(GATE CS 2003)中用作赋值语句的左侧,哪个不会给出编译时错误?

(A) 一、 仅限II和IV (B) 二、 仅限III和IV

(C) 仅限II和IV (D) 仅限IV 答复: (A) 说明: 请参见下面的解释。

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;
}

这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享