1 votes 1 votes main() { int a; scanf("%i"&a); printf("%i %d",a,a); scanf("%d",&a); printf("%i %d",a,a); } suppose user entered 0101 as input .what is printed by above program? Programming in C programming-in-c non-gate + – eyeamgj asked Nov 22, 2017 retagged Nov 22, 2017 by Arjun eyeamgj 733 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 5 votes 5 votes The difference between %i and %d is that when used with scanf(), then %d always takes a decimal integer, whereas %i recognizes the 0 and 0x prefixes as octal and hexadecimal. So when input is given as 0101 0101 then 1st printf() output: 65 65 (octal value of 0101) 2nd printf() output: 101 101 (it simply ignores prefix 0) kirti_k answered Nov 22, 2017 selected Nov 24, 2017 by eyeamgj kirti_k comment Share Follow See all 7 Comments See all 7 7 Comments reply just_bhavana commented Nov 22, 2017 reply Follow Share online compiler is giving 65 65 65 65 0 votes 0 votes hs_yadav commented Nov 22, 2017 reply Follow Share just_bhavana here the question is asked for separate input...but in your case you are providing i/p only one time ...and it is scaned by first scanf...and next time old values of a is used for ....and if you run it on other system compiler then it will ask for i/p.... 1 votes 1 votes just_bhavana commented Nov 22, 2017 reply Follow Share yes, missed it. thank you @hs_yadav 0 votes 0 votes Arjun commented Nov 22, 2017 reply Follow Share @kirti_k Copy pasting is not expected here 0 votes 0 votes Arjun commented Nov 22, 2017 reply Follow Share See what you did is CTRL+C, CTRL+V from stackoverflow and you did not even give a reference link to it as mandated by stackoverflow in their terms and condition. This is not a good way to share knowledge. 1 votes 1 votes Hira Thakur commented Nov 22, 2017 reply Follow Share how the input 0101 is providing 2 times, so that it prints 65,65 ?? 0 votes 0 votes kirti_k commented Nov 22, 2017 reply Follow Share okay I'm sorry sir it won't happen again :) 0 votes 0 votes Please log in or register to add a comment.