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 what math functions are available for integers? For floating point?
What is meant by 'bit masking'?
How we can insert comments in a c program?
What is return type in c?
I need testPalindrome and removeSpace
#include
What do mean by network ?
Explain how do you generate random numbers in c?
What is external variable in c?
What is boolean in c?
What is new line escape sequence?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
What are static variables in c?
What is the Purpose of 'extern' keyword in a function declaration?
What is self-referential structure in c programming?
When do we get logical errors?