3,636 views
7 votes
7 votes
consider the statements

putchar (getchar());

putchar (getchar());

if

a

b    is the input , the output will be

  a)ab                        b)a  b

 c)an error message  d)this can not be the input

2 Answers

10 votes
10 votes
Answer will be option D. As, '\t' and '\n' is considered as input in getchar(). So if we try to give the input as
a
b
the second getchar() will take '\n' as input.
Even if we try to give the input as 'a b' the output will be only 'a', cause the 2nd getchar() will take '\t' as input.
But if we give 'ab' as input, then the 2nd getchar() will consider 'b' as it's input, so the o/p will be 'ab'.
If you remove the 2nd putchar() line and try with 'ab', you will get to understand the 1st one will only put 'a' as o/p in the stdout.
3 votes
3 votes
This wont give any error, output depends on the way input is provided. If input is 'ab' then output will be 'ab', if input is 'a b' output will be 'a ' assuming that you have not made any mistake in the format of question, the input seems to be 'a\nb', so output will be 'a\n'.

I think D will be the right.choice, as there is no option for 'None of these'.

Related questions

1 votes
1 votes
1 answer
1
Hira Thakur asked Jun 23, 2017
1,368 views
what is difference between getc() getch(), getche(),getchar()???is getc() and getchar() is same???
0 votes
0 votes
1 answer
2
0 votes
0 votes
2 answers
3
Aspi R Osa asked Dec 13, 2015
1,628 views
Consider the following program fragment:char c= ‘a’while (c++ ≤ ‘z’)putchar (xxx);if the required output is abcdefghijklmnopqrstuvwxyz then xxx should be:c-1cc+...