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
Differentiate Source Codes from Object Codes
How does normalization of huge pointer works?
Is main is a keyword in c?
What is function and its example?
What is chain pointer in c?
What are Macros? What are its advantages and disadvantages?
What is an arrays?
Can a local variable be volatile in c?
Explain what is meant by high-order and low-order bytes?
Suggesting that there can be 62 seconds in a minute?
Can the “if” function be used in comparing strings?
How can I open a file so that other programs can update it at the same time?
What happens if you free a pointer twice?
Explain the use of 'auto' keyword in c programming?
Process by which one bit pattern in to another by bit wise operation is?