bookk
closed

closed by
231 views
0 votes
0 votes
closed as a duplicate of: ISRO2016-25
What will be the output of the following program? Assume that you are running this program in little-ending processor.
#include<stdio.h>
int main()
{
short a=320;
char *ptr;
ptr=(char *)&a;
printf("%d",*ptr);
return 0;
}
closed by

1 Answer

Best answer
0 votes
0 votes

In this program, a character pointer ptr is pointing to an integer a. Since size of character is 1 byte when the character pointer is de-referenced it will contain only first byte of integer. If machine is little endian then *ptr will be 64 (because last byte is stored first).

Since 320 : 101000000. So last 8 bit is printed that is 64 (1000000)

Little Endian : In little endian machines, last byte of binary representation of the multibyte data-type is stored first.

Feel free to ask.
Thank You.

 

selected by

Related questions

0 votes
0 votes
1 answer
2
amit166 asked Sep 6, 2018
331 views
Solution of $T(n)=\sqrt{n}T(\sqrt{n})+n$
2 votes
2 votes
4 answers
3
srestha asked Apr 24, 2019
3,742 views
Which of the following data structure is efficient to implement priority queue such as insertion ,deletion, searching?A)Linked ListB)HeapC)Sorted ArrayD)Unsorted ArrayHow...
0 votes
0 votes
1 answer
4
Ram Swaroop asked Jan 27, 2019
1,263 views
Consider the hashing table with 'm' slots and 'n' keys. If the expected number of probes in unsuccessful search is 3. The expected number of probes in a successful search...