Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Differentiate Source Codes from Object Codes

1665


How does normalization of huge pointer works?

1231


Is main is a keyword in c?

1176


What is function and its example?

1273


What is chain pointer in c?

1116


What are Macros? What are its advantages and disadvantages?

1222


What is an arrays?

1139


Can a local variable be volatile in c?

1056


Explain what is meant by high-order and low-order bytes?

1092


Suggesting that there can be 62 seconds in a minute?

1105


Can the “if” function be used in comparing strings?

1110


How can I open a file so that other programs can update it at the same time?

1242


What happens if you free a pointer twice?

1136


Explain the use of 'auto' keyword in c programming?

1185


Process by which one bit pattern in to another by bit wise operation is?

1229