+ 1

Can anyone explain this code

#include <stdio.h> extern int x; int main() { do{ do{ printf("%o", x); } while(!-2); } while(0); return 0; } int x =8;

21st Nov 2019, 8:18 AM
Preity
Preity - avatar
9 ответов
+ 1
%o is for octal number. 1000 -> this is 8 in binary For octal you group three elements from LSB but 1 will be left out alone. So to get 3 bit combination you add two 0's before 1. 001000 -> now if you group 3 bits from right you get 0 and three bits on left will give you 1. So your output is 10. Also if you did not understand the while loop then both are false since -2 will give true but the ! operator results in false.
21st Nov 2019, 8:49 AM
Avinesh
Avinesh - avatar
+ 1
AnonymousGuy yeah for confusing people thanks for help 👍
21st Nov 2019, 9:21 AM
Preity
Preity - avatar
+ 1
External is a storage class like auto ,static I think it is global
22nd Nov 2019, 5:22 PM
Lonely Traveller
Lonely Traveller - avatar
0
Yeah..like Avinesh said the code simply converts an integer in octal value... But I would like to ask you Preity.. from where you found this code?? Bcoz I don't see any use of two do-while loops in this code..
21st Nov 2019, 8:53 AM
Alaska
Alaska - avatar
0
Thanks @all
21st Nov 2019, 9:18 AM
Preity
Preity - avatar
0
AnonymousGuy I'm preparing for Gate and these all questions are in question bank of gate which in referring
21st Nov 2019, 9:19 AM
Preity
Preity - avatar
0
Preity Okay..Then I guess these loops are just for confusing people😅
21st Nov 2019, 9:20 AM
Alaska
Alaska - avatar