Question

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

Option 3 : 12

Advertisement

Detailed Solution

सही उत्तर 12 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

On a system where int occupies 4 bytes, what is the output of the following C program? struct S { char c; int i; char d; }; printf("%zu", sizeof(struct S)); / उस सिस्टम पर जहाँ int 4 बाइट लेता है, निम्नलिखित C प्रोग्राम का आउटपुट क्या है?

1.
6
2.
9
3.
12
4.
10

Correct Answer: 12

The char c is followed by 3 padding bytes so that int i starts at a 4-byte boundary; after i, the trailing char d needs 3 more padding bytes to make the struct size a multiple of the strictest alignment (4). Total = 1 + 3 + 4 + 1 + 3 = 12 bytes. / char c के बाद 3 पैडिंग बाइट आती हैं ताकि int i 4-बाइट सीमा से शुरू हो; i के बाद अंतिम char d के लिए 3 और पैडिंग बाइट चाहिए ताकि संरचना का आकार कठोरतम एलाइनमेंट (4) का गुणज हो। कुल = 1 + 3 + 4 + 1 + 3 = 12 बाइट।

Downloaded from PrepSnap (prepsnap.in)