Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 3 : `*(a[1] + 0)` / `*(a[1] + 0)`

Advertisement

Detailed Solution

सही उत्तर `*(a[1] + 0)` / `*(a[1] + 0)` है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

For the C declaration `int a[3][2] = {{1, 2}, {3, 4}, {5, 6}};`, which of the following expressions does NOT evaluate to 4? / C घोषणा `int a[3][2] = {{1, 2}, {3, 4}, {5, 6}};` के लिए, निम्नलिखित में से कौन-सा व्यंजक 4 का मान नहीं देता है?

1.
`a[1][1]` / `a[1][1]`
2.
`*(*(a + 1) + 1)` / `*(*(a + 1) + 1)`
3.
`*(a[1] + 0)` / `*(a[1] + 0)`
4.
`*(&a[0][0] + 3)` / `*(&a[0][0] + 3)`

Correct Answer: `*(a[1] + 0)` / `*(a[1] + 0)`

`a[1][1]` is row 1, column 1 = 4; `*(*(a + 1) + 1)` dereferences the same element = 4; `*(&a[0][0] + 3)` steps three ints past `a[0][0]` through the flat row-major layout (1, 2, 3, 4), landing on 4. But `*(a[1] + 0)` is just `a[1][0]` = 3, so (c) is the odd one out. The trap is reading `*(a[1] + 0)` as the second element of row 1. / `a[1][1]` पंक्ति 1, स्तंभ 1 = 4 है; `*(*(a + 1) + 1)` उसी तत्व को dereference करता है = 4; `*(&a[0][0] + 3)` फ्लैट row-major लेआउट (1, 2, 3, 4) में `a[0][0]` से तीन int आगे बढ़कर 4 पर पहुँचता है। लेकिन `*(a[1] + 0)` केवल `a[1][0]` = 3 है, अतः (c) ही भिन्न है। जाल `*(a[1] + 0)` को पंक्ति 1 का दूसरा तत्व पढ़ना है।

Downloaded from PrepSnap (prepsnap.in)