Assume the following C variable declaration C int *A [10], B[10][10]; Of the…

2003

Assume the following C variable declaration 

C

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

Of the following expressions :

  1. A[2] 

  2. A[2][3] 

  3. B[1]

  4. B[2][3] 

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

Answer: A. I, II, and IV onlyGiven the declarations: int *A[10], B[10][10]; A[2]: A is an array of pointers to int, so A[2] has type int*. This is an assignable lvalue (you can assign a…

  1. A.

    I, II, and IV only

  2. B.

    II, III, and IV only

  3. C.

    II and IV only

  4. D.

    IV only

Attempted by 155 students.

Show answer & explanation

Correct answer: A

Given the declarations: int *A[10], B[10][10];

  • A[2]: A is an array of pointers to int, so A[2] has type int*. This is an assignable lvalue (you can assign a pointer value to it).

  • A[2][3]: This is equivalent to *(A[2] + 3). It names an int element (after dereferencing), so it is an assignable int lvalue.

  • B[1]: B is an array of arrays (type int[10][10]), so B[1] has type int[10], an array. Entire arrays are not assignable in C, so B[1] cannot be the left-hand side of an assignment.

  • B[2][3]: This refers to an int element of the two-dimensional array and is an assignable int lvalue.

Conclusion: The expressions that can be used as left-hand sides are A[2], A[2][3], and B[2][3]. B[1] cannot be used because it is an array and arrays cannot be assigned to.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…