1

Below is the C program and the output is 201. I have no idea how this is possible. Please explain this.

#include <stdio.h>
  int main() {
    int number = 288;
    char * ptr;
    ptr = (char * ) & number;
    printf("%x", * ptr);
    ptr++;
    printf("%x", * ptr);
    return 0;
  }

This is in case of little endian machine. This question was asked in the MCQ contest on geeksforgeeks. But they provided no explaination of it.

Brij Raj Kishore
  • 1,595
  • 1
  • 11
  • 24

1 Answers1

2

The 201 is perfectly reasonable (on little-endian systems):

The variable number starts with these two bytes (on little-endian systems): 0x20, 0x01.

Bernd Elkemann
  • 23,242
  • 4
  • 37
  • 66