answersLogoWhite

0

The data elements of a structure are laid out according to the order they are declared. Padding bytes may also be inserted between members to ensure all members are correctly aligned. Memory alignment can be user-defined, however it's generally better to align objects according to the underlying architecture. For instance, on a 32-bit system the underlying architecture has a 4-byte word length, thus an object that is equal or greater in length is best aligned upon a 4-byte boundary to keep memory access cycles to a minimum. Types that are smaller than the word length are usually aligned so that they do not cross a word boundary, such that a single 4-byte word can store 4 char types, 2 shorts, or 2 chars and 1 short. If the total size of the structure crosses a word boundary, padding bytes are inserted after the final member so the total size is an exact multiple of the word length. However, if the total size is less than a single word length to the extent that two or more structures may fit within a word, no padding bytes are required.

Given that each structure member is positioned at a constant zero-based offset from the start address of the structure, the compiler can use trivial pointer arithmetic to access the individual members of an instance of the structure, just as easily as it can calculate the address of an array element from its zero-based suffix (index).

User Avatar

Wiki User

9y ago

Still curious? Ask our experts.

Chat with our AI personalities

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra

Add your answer:

Earn +20 pts
Q: How are the data elements of a structure accessed and processed explain?
Write your answer...
Submit
Still have questions?
magnify glass
imp