Question

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

Option 4 : 5 / 5

Advertisement

Detailed Solution

सही उत्तर 5 / 5 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following C code? `int a[] = {1, 2, 3, 4, 5}; printf("%d", sizeof(a) / sizeof(a[0]));` / निम्नलिखित C कोड का आउटपुट क्या होगा? `int a[] = {1, 2, 3, 4, 5}; printf("%d", sizeof(a) / sizeof(a[0]));`

1.
20 / 20
2.
4 / 4
3.
1 / 1
4.
5 / 5

Correct Answer: 5 / 5

`sizeof(a)` is 5 × 4 = 20 bytes and `sizeof(a[0])` is 4 bytes, so the division yields the element count 5. The trap is printing `sizeof(a)` alone (20) or assuming the array decays to a pointer here — it does not, because `sizeof` is one of the exceptions. / `sizeof(a)` है 5 × 4 = 20 बाइट और `sizeof(a[0])` है 4 बाइट, अतः भाग देने पर तत्वों की संख्या 5 मिलती है। जाल अकेले `sizeof(a)` (20) को छापना है, या यह मानना कि array यहाँ pointer में decay होगा — नहीं होगा, क्योंकि `sizeof` उन अपवादों में से एक है।

Downloaded from PrepSnap (prepsnap.in)