6,043 views

Consider the following program

{
int x=1;
printf("%d",(*char(char*)&x));
}

Assuming required header files are included and if the machine in which this program is executed is little endian, then the output will be

1. 0
2. 99999999
3. 1
4. unpredictable

In that case, the answer would be 1. But since they have used *char, it won't work. We don't need to typecast it(again) to get the value stored at the char pointer.
which year of ISRO paper is this?
22 april 2018

https://www.geeksforgeeks.org/little-and-big-endian-mystery/

useful to understand Big endian and little endian.

Subscribe to GO Classes for GATE CSE 2022

main()
{
int x=1;
printf("%d",(*char(char*)&x));
}

Here,we will get a compilation error because 'char' is extra.

If the code is :

main()
{
int x=1;
printf("%d",(*(char*)&x));
}

OUTPUT: 1 option(c)

by
55 137 249

Yes u r right..then which option is correct....?
We can challenge this question,I suppose.
ok..done
I too marked it (c) i.e. 1

But due to compilation error in the actual code, none of the options is correct.
What is answer in ISRO key
Given the option then I feel Option $\mathbf{(d)}$ is safe to mark.
Little endian is given, so A
by
6

What will be the output if Big Endian was given?
if its big endian the number 1 can be represented as 00000001 00000000 00000000 00000000 if int occupies four bytes hence the answer will be 1.

1
4,154 views
1 vote