4,791 views

4 Answers

1 1 vote
short variable has a 16-bit size. in a little-endian system, 320 (=00000001 01000000b) will be stored as 01000000 in the first location and  00000001 in the next location.

char variable stores 8 bits and points to 01000000 whose equivalent decimal value is 64. Thus output will be 64
• edited by
1 1 vote

 

Here, (C) is the answer.

Here, a = $(320)_{10}$ = $(0000000101000000)_{2}$ = $(0140)_{16}$.

Short data type takes 2 bytes of memory.

*ptr is char pointer which points to the 1 byte memory location of stored value of variable a.

In little-endian representation of stored data is as least significant byte of stored value will be stored in first memory location and second least byte will be stored on subsequent memory locations and so on.

Refer, Endianness for more clarity on little-endian.

Suppose address of variable a is start at location A in byte addressable memory architecture. than $(40)_{16}$ will be store at location A and $(01)_{16}$ will be stored at address A+1 .

 

Little-Endian representation
$(40)_{16}$ $(01)_{16}$

 

Here, ptr points to the memory address A.

Here, *ptr prints the integer value of the byte stored on location A. which is $(40)_{16}$ = $(64)_{10}$.

 

 

 

0 0 votes

We know in binary 320 = 00000001 01000000 .

In little – endian we take values from the LSB , char will take 1 byte , so 01000000  will be taken  = 64.

Answer – C :  64

Position:
Show:

Related questions

1 1 vote
1 1 answer
314
314 views
khanshahima4 asked Sep 24
314 views
1. If precedence tells me which operator has priority, and associativity tells me how to handle operators at the same level, then why do I need a separate concept called ...
14 14 votes
1 1 answer
1.4k
1.4k views
GO Classes asked Jul 2
1,384 views
Assume:$\texttt{short = 2 bytes}$, $\texttt{int = 4 bytes}$, $\texttt{char = 1 byte}$$\texttt{int}$ needs $4$-byte alignment and the final structure size is rounded to a ...
18 18 votes
2 2 answers
770
770 views
GO Classes asked Jul 2
770 views
Assume:struct Student { double gpa; }; struct Student alice; struct Student *sptr = &alice;Which of the following correctly assigns $\texttt{4.0}$ to $\texttt{alice.gpa}$...
10 10 votes
1 1 answer
574
574 views
GO Classes asked Jul 2
574 views
Consider the following code idea from the source:typedef struct { double x, y; } Point; void reset(Point p) { p.x = p.y = 0; } int main() { Point a = {12.0, 42.0}; Point ...