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; } DS programming-in-c + – amit166 asked Sep 18, 2018 closed Sep 19, 2023 by Hira Thakur amit166 231 views comment Share Follow See 1 comment See all 1 1 comment reply Shaik Masthan commented Sep 18, 2018 reply Follow Share represent 320 in binary access only 8 LSB bits, ( why 8 bits only? due to char can have only 8 bits ) 0 votes 0 votes Please log in or register to add a comment.
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. Sakshi Jaiswal answered Sep 30, 2018 selected Oct 17, 2018 by Mk Utkarsh Sakshi Jaiswal comment Share Follow See all 0 reply Please log in or register to add a comment.