TCS
Company
Programming
Arrays
Predict the output of following code:
main()
{
if( printf(“”)) // prints content of printf statement and
//takes length of the string for if case
case its 1, So true
printf(“Face”);
else
printf(“Focus”);
}
1. Error
2. Face
3. “”Focus
4. Face
Read Solution (Total 9)
-
- There are two cases here:
FIRST:: if( printf(""))
printf("Face");
else
printf("Focus");
If these is case then output should be Foucs, AND it is not given in the option.
SECOND CASE: if( printf(" ")) //space inside printf statement
printf("Face");
else
printf("Focus");
In second case the output should be _Focus.... where _ represents space. - 6 years agoHelpfull: Yes(3) No(5)
- In the above case some compilers shows warring and some shows output ....
So the actual output is FOCUS . - 6 years agoHelpfull: Yes(3) No(0)
- Actually the built-in function printf( ) returns the integer corresponding to number of characters it prints, now coming to your query
printf(“”);
Here printf returns 0 since, the count of characters it printed is 0.
‘’-0
if(0) is false ( if (any positive integer ) is always true )so the body of “else” will be executed. - 6 years agoHelpfull: Yes(2) No(0)
- (1) Error because case its 1, so true are not in the comment line it is written in next line
- 6 years agoHelpfull: Yes(0) No(1)
- if statement is true so the output will be true part""Focus
- 6 years agoHelpfull: Yes(0) No(1)
- if condition is false so it takes the false part
the answer is 3 - 6 years agoHelpfull: Yes(0) No(0)
- printf returns number of characters that it prints
out put should be Face - 6 years agoHelpfull: Yes(0) No(2)
- since printf in if part is used to print the characters .
if(printf("")) will be zero hence else part will be executed
ans:focus - 6 years agoHelpfull: Yes(0) No(0)
- Face.
The if codtion works as true one. - 5 years agoHelpfull: Yes(0) No(0)
TCS Other Question