Skip to content

ISRO Scientist/Engineer CSE 2020Programming in C › Pointers and Arrays

ISRO Scientist/Engineer CSE 2020 PYQ: What is output of the following ‘C’ code assuming it runs on a byte addressed little endian machine?…

What is output of the following ‘C’ code assuming it runs on a byte addressed little endian machine?

#include<stdio.h>
int main()
{
    int x;
    char *ptr;
    x=622,100,101;
    printf("%d",(*(char *)&x)*(x%3));
    return 0;
}
  1. A
    622
  2. B
    311
  3. C
    22
  4. D
    110
    Correct answer

Answer

(D) $110$

Approach

The comma operator has lower precedence than assignment, so x = 622, 100, 101 assigns 622 to x and discards the rest. On a little-endian byte-addressed machine, the first byte of x is its least significant byte. Compute that byte and multiply by x % 3.

Reviewed by ISRO IQ Editorial Team.