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 the advantages of using macro in c language?
Are pointers integer?
Is there sort function in c?
What are the 4 types of unions?
What is the difference between call by value and call by reference in c?
Write a program to print fibonacci series using recursion?
write a program to find the given number is prime or not
What is the significance of c program algorithms?
Explain the use of bit fieild.
What are the different types of linkage exist in c?
What are the different types of constants?
Is c programming hard?
What are # preprocessor operator in c?
find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }
Define and explain about ! Operator?