void main()
{
char c;
while(c=getchar()!='\n')
printf("%d",c);
}
o/p=11 why?
Answer Posted / suman halder
test cases:
1.
i/p:hi
o/p:11
2.
i/p:hello
o/p:11111
actually,getchar reads from stdin and is line buffered which means it will not return until you press ENTER.
so,look at the evaluation of the expression(c=getchar()!='\n')
here,
getchar()!='\n' evaluates to true until and unless u'll hit enter..that is why,the actual evaluation would look like
(c=(getchar()!='\n'))
so,
1 will be stored into c each time u press a key except enter key as (getchar()!='\n') evaluates to 1(true value of an expression).
finally,content of the buffer would get printed..
thats it..
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Explain output of printf("Hello World"-'A'+'B'); ?
What is the explanation for cyclic nature of data types in c?
What is an arrays?
Tell me is null always defined as 0(zero)?
Array is an lvalue or not?
How does pointer work in c?
Where are local variables stored in c?
Explain what are its uses in c programming?
C language questions for civil engineering
What is type qualifiers?
How can I invoke another program (a standalone executable, or an operating system command) from within a c program?
how to execute a program using if else condition and the output should enter number and the number is odd only...
What are the modifiers available in c programming language?
What is derived datatype in c?
Explain what is a const pointer?