+ 3

How does the output comes as 8 in this code

Doubt in output https://code.sololearn.com/cqt5AU0c8bnm/?ref=app

27th Jan 2021, 9:49 AM
Yogeshwaran P
Yogeshwaran P - avatar
5 Antworten
+ 6
This is because numeric constants beginning with a 0 are interpreted as octals numbers ( base 8 ) which when converted to decimal (base 10) (via the format specifier "%d") yields 8 as answer
27th Jan 2021, 10:01 AM
Arsenic
Arsenic - avatar
27th Jan 2021, 9:56 AM
Atul
Atul - avatar
+ 3
Yogeshwaran you can't do that directly in C, you have to write your own function to do perform conversion. Here is an example ( I used bitwise operations here but you can also go for conventional method ) https://code.sololearn.com/cynQpl8R7b1q/?ref=app
27th Jan 2021, 1:01 PM
Arsenic
Arsenic - avatar
+ 1
Thank you Arsenic ☺️👍
27th Jan 2021, 1:03 PM
Yogeshwaran P
Yogeshwaran P - avatar
0
Thank you very much Arsenic and Atul 😃....... Can you please also tell me,how to represent base2 number in integer variable?
27th Jan 2021, 12:31 PM
Yogeshwaran P
Yogeshwaran P - avatar