Structure
Question 1 |
Following declaration of an array of struct, assumes size of byte, short, int and long are 1,2, 3 and 4 respectively. Alignment rule stipulates that n-byte field must be located at an address divisible by n, the fields in a struct are not rearranged, padding is used to ensure alignment. All elements of array should be of same size.
Struct complex
Short s
Byte b
Long l
Int i
End complex
Complex C[10]
Assuming C is located at an address divisible by 8 , what is the total size of C, in bytes?
Struct complex
Short s
Byte b
Long l
Int i
End complex
Complex C[10]
Assuming C is located at an address divisible by 8 , what is the total size of C, in bytes?
150 | |
160 | |
200 | |
240 |
Question 2 |
To sort many large objects or structures, it would be most efficient to place
them in an array and sort the array | |
pointers to them in an array and sort the array | |
them in a linked list and sort the linked list | |
references to them in an array and sort the array |
Question 2 Explanation:
● Pointers will point to large objects or structures.
● By using pointers we will easily access the large objects or structures with the help the addresses pointing to them.
● If you made any changes to the elements in the array, it automatically reflect as these are pointed by the pointers
● By using pointers we will easily access the large objects or structures with the help the addresses pointing to them.
● If you made any changes to the elements in the array, it automatically reflect as these are pointed by the pointers