in Programming recategorized by
6,043 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 recategorized by
by
2439 3623 5536
6.0k views

5 Comments

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.
0
0
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

Subscribe to GO Classes for GATE CSE 2022

2 Answers

16 votes
16 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
55 137 249

6 Comments

Yes u r right..then which option is correct....?
0
0
We can challenge this question,I suppose.
1
1
ok..done
0
0
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
5 votes
5 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