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 0 99999999 1 unpredictable Programming in C isro2018 programming output + – Arjun asked Apr 22, 2018 • retagged Dec 9, 2022 by Lakshman Bhaiya Arjun 8.6k views answer comment Share Follow See all 9 Comments See all 9 9 Comments reply Vikas Yadav 1 commented Apr 22, 2018 reply Follow Share A. 0 0 votes 0 votes Akhilesh Singla commented Apr 22, 2018 reply Follow Share I think, it should be either "no output"(gcc) or "error"(zapcc) depending on the type of compiler used. The problem is with "*char" part because we don't need to typecast it again to access the value stored at the type-casted char pointer. Thus, option D should be the answer. 0 votes 0 votes srestha commented Apr 22, 2018 reply Follow Share unpredictable means undefined behavior? It is working on certain value 1, then why will be undefined behavior? Moreover it is working on little endian machine 1 votes 1 votes Akhilesh Singla commented Apr 22, 2018 reply Follow Share It gives the below error: 0 votes 0 votes srestha commented Apr 23, 2018 reply Follow Share Here integer typecasting to char pointer Without last pointer code will work 1 votes 1 votes Akhilesh Singla commented Apr 23, 2018 reply Follow Share 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 votes 0 votes srestha commented Jun 8, 2018 reply Follow Share which year of ISRO paper is this? 0 votes 0 votes saumya mishra commented Jun 8, 2018 reply Follow Share 22 april 2018 0 votes 0 votes Ollie commented Jul 2, 2020 reply Follow Share https://www.geeksforgeeks.org/little-and-big-endian-mystery/ useful to understand Big endian and little endian. 2 votes 2 votes Please log in or register to add a comment.
Best answer 18 votes 18 votes 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) VS answered Apr 23, 2018 • selected Apr 25, 2018 by Arjun VS comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments cs2019 commented Apr 23, 2018 reply Follow Share I too marked it (c) i.e. 1 But due to compilation error in the actual code, none of the options is correct. 0 votes 0 votes anchitjindal07 commented Dec 1, 2018 reply Follow Share What is answer in ISRO key 0 votes 0 votes `JEET commented Jan 2, 2020 reply Follow Share Given the option then I feel Option $\mathbf{(d)}$ is safe to mark. 0 votes 0 votes Please log in or register to add a comment.
6 votes 6 votes Little endian is given, so A Vikas Yadav 1 answered Apr 22, 2018 Vikas Yadav 1 comment Share Follow See all 2 Comments See all 2 2 Comments reply elliotalderson commented Oct 25, 2019 reply Follow Share What will be the output if Big Endian was given? 0 votes 0 votes tamilselvan302 commented Nov 24, 2019 reply Follow Share 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 votes 0 votes Please log in or register to add a comment.