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
What are 'near' and 'far' pointers?
Should a function contain a return statement if it does not return a value?
What are the basic data types associated with c?
what is the syallabus of computer science students in group- 1?
What is the scope of local variable in c?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What is data structure in c and its types?
How can I remove the leading spaces from a string?
Differentiate between the = symbol and == symbol?
Write a program to swap two numbers without using a temporary variable?
What are compound statements?
a program that can input number of records and can view it again the record
Here is a good puzzle: how do you write a program which produces its own source code as output?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
What are the disadvantages of c language?