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

2018

Assume the following C variable declaration:

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

Among the following expressions, which will not give compile time errors if used as left-hand side of assignment statements in a C program?

I. A[2] II. A[2][3] III. B[1] IV. B[2][3]

  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 68 students.

Show answer & explanation

Correct answer: A

Expression I: AValid LHS

  • A is a collections of 10 pointer variables. A targets the third pointer variable inside that array. Because it is a normal pointer variable, its value (the memory address it holds) can be updated at any time.

Expression II: AValid LHS

  • Because A is an int* pointer, attaching a second subscript `` instructs the compiler to perform pointer arithmetic. It travels to the memory address stored in A, moves 3 integer steps forward, and looks at that specific integer. Since it resolves to a regular int variable in memory, you can overwrite it.

Expression III: BInvalid LHS (Triggers Compile Error)

  • Feedback: B is a 2D array, which means it is an array of arrays. B references the entire second row (an array of 10 integers). In C, an array name or row identifier decays into a constant pointer to its first element. You cannot assign anything to a constant pointer, nor can you overwrite an entire array block at once using an assignment operator.

Expression IV: BValid LHS

  • While you cannot assign a value to an entire row (like B), you absolutely can assign a value to an individual element inside a row. B pinpoints the specific single integer at row 2, column 3. It is a modifiable l-value.

Explore the full course: Up Lt Grade Assistant Teacher 2025