in Programming in C retagged by
8,495 views
5 votes
5 votes

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 Programming in C retagged by
by
8.5k views

4 Comments

which year of ISRO paper is this?
0
0
22 april 2018
0
0

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

useful to understand Big endian and little endian.

2
2

2 Answers

18 votes
18 votes
Best answer
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)

selected by
by

4 Comments

I too marked it (c) i.e. 1

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

2 Comments

What will be the output if Big Endian was given?
0
0
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.
0
0
Answer:

Related questions