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
How do you initialize pointer variables?
How pointers are declared?
What is the mean of function?
I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
What are the features of the c language?
Write a C program in Fibonacci series.
Write a program to generate the Fibinocci Series
What is an array? What the different types of arrays in c?
how should functions be apportioned among source files?
Write a program to reverse a linked list in c.
How can I use a preprocessorif expression to ?
What is the difference between fread buffer() and fwrite buffer()?
What are the usage of pointer in c?
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory