Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

ISRO | ISRO CS 2016 | Question 22

  • Last Updated : 23 Mar, 2018

What will be output of the following program? Assume that you are running this program in little-endian processor.




#include<stdio.h>
  
int main() {
    short a = 320;
    char * ptr;
    ptr = (char * ) & a;
    printf("%d", * ptr);
    return 0;
}

(A) 1
(B) 320
(C) 64
(D) Compilation error


Answer: (C)

Explanation: Big Endian Byte Order: The most significant byte of the data is placed at the byte with the lowest address. The rest of the data is placed in order in the next three bytes in memory.

Little Endian Byte Order: The least significant byte of the data is placed at the byte with the lowest address. The rest of the data is placed in order in the next three bytes in memory.

a= 320, 2-byte representation of a:

But as we are using little-endian format here, so it would actually stored in memory like :

ptr which is a character pointer, on dereferencing will output a single byte, i.e the first byte: (01000000)2 which is equal to 64.
So, the correct option is (C).


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!