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 is c definition?
Explain the difference between strcpy() and memcpy() function?
What is file in c preprocessor?
What is difference between function overloading and operator overloading?
What is calloc in c?
What should malloc() do? Return a null pointer or a pointer to 0 bytes?
Why is not a pointer null after calling free?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
Add Two Numbers Without Using the Addition Operator
What is the use of typedef in structure in c?
Mention four important string handling functions in c languages .
What is const volatile variable in c?
What is volatile, register definition in C
What does nil mean in c?