...
C-Programming
August 27, 2024
Database-Management-System
August 27, 2024
C-Programming
August 27, 2024
Database-Management-System
August 27, 2024

C-Programming

Question 51

What is the output of the following ‘C’ program ? (Assuming little – endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address.)

#include <stdio.h> #include <stdlib.h> /* Assume short int occupies two bytes of storage */  int main ()  {         union saving         {             short int one;             char two[2];         };         union saving m;         m.two [0] = 5;         m.two [1] = 2;         printf("%d, %d, %d\n", m.two [0], m.two [1], m.one);  }/* end of main */  
A
5, 2, 1282
B
5, 2, 52
C
5, 2, 25
D
5, 2, 517
Question 51 Explanation: 
• m.two[0] holds the value 5 and m.two[1] holds the value 2. So, it will print 5 and 2 values.
• Size of the short integer is 2 bytes. Saving is union variable, we will access one variable at time and only one memory location is shared among all the members. So, the two values 5 and 2 (two bytes of the data) will store in little endian format in the variable m.one.
• Endianness is the sequential order in which bytes are arranged into larger numerical values when stored in memory or when transmitted over digital links.
• In big-endian format, whenever addressing memory or sending/storing words bytewise, the most significant byte—the byte containing the most significant bit—is stored first (has the lowest address) or sent first, then the following bytes are stored or sent in decreasing significance order.
• Little-endian format reverses this order: the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address).
• First 5 will store in the lowest address and 2 will store next highest address.
• So the binary representation 5 and 2 in little endian format is
00000010 00000101.
The binary number of the above is 517.
Correct Answer: D
Question 51 Explanation: 
• m.two[0] holds the value 5 and m.two[1] holds the value 2. So, it will print 5 and 2 values.
• Size of the short integer is 2 bytes. Saving is union variable, we will access one variable at time and only one memory location is shared among all the members. So, the two values 5 and 2 (two bytes of the data) will store in little endian format in the variable m.one.
• Endianness is the sequential order in which bytes are arranged into larger numerical values when stored in memory or when transmitted over digital links.
• In big-endian format, whenever addressing memory or sending/storing words bytewise, the most significant byte—the byte containing the most significant bit—is stored first (has the lowest address) or sent first, then the following bytes are stored or sent in decreasing significance order.
• Little-endian format reverses this order: the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address).
• First 5 will store in the lowest address and 2 will store next highest address.
• So the binary representation 5 and 2 in little endian format is
00000010 00000101.
The binary number of the above is 517.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!