+ 1

What is the output of the code?? when input is 4 c.................

#include <stdio.h> int main() { int a; char c; scanf("%d%c",&a,&c); printf("%d%c",a,c); return 0; } 4 c is wrong answer :->

14th Mar 2018, 12:43 PM
Akshay Jain
Akshay Jain - avatar
6 Answers
+ 4
The next character value is assigned to c, in Code Playground we can test this by changing the printf format with "%d%d" then in Code Playground input dialog if you type '4 c' the output would be '432' and if we type '4', {Enter} and type 'c' the output would be 410. Notice what came after 4, in the first input '4 c' there's a space between 4 and 'c' and space ASCII code is 32, hence '432'. The same with '410', ASCII code for line break is 10. Hth, cmiiw
14th Mar 2018, 1:34 PM
Ipang
+ 3
right ans is 4
14th Mar 2018, 2:30 PM
Akshay Jain
Akshay Jain - avatar
+ 3
yes if u consider after 4 there is a space then printf only print 4
14th Mar 2018, 2:39 PM
Scooby
Scooby - avatar
+ 2
4c is ans
14th Mar 2018, 12:47 PM
Scooby
Scooby - avatar
+ 2
No
14th Mar 2018, 12:51 PM
Akshay Jain
Akshay Jain - avatar
+ 2
but here in code %d%c.. so 4c isn't right ans?
14th Mar 2018, 2:28 PM
Scooby
Scooby - avatar