TCS
Company
Programming
Program
Predict the output of following code:
main()
{
printf(“ %d ”,printf(“ FACE ”)); //valid
}
1.FACE4
2. Error
3. Garbage value
4. FACE
Read Solution (Total 23)
-
- The answer is "FACE 4". As inner printf will print the "FACE" directly but when outer printf comes there is a %d mentioned which means integer value. So, the length of FACE is returned that is 4.
- 6 years agoHelpfull: Yes(6) No(1)
- there is space is also counted.. so output is FACE 6
if there is no space then output FACE4 - 6 years agoHelpfull: Yes(3) No(1)
- error as it is not an int value
- 6 years agoHelpfull: Yes(2) No(0)
- ANS :1.FACE4
- 6 years agoHelpfull: Yes(2) No(0)
- printf and scanf returns an integer. most of the time we don't save or use that integer. btw printf returns the number char it printed and scanf returns the number of input it too. like printf("arif") will return 4.
so printf(“ %d ”,printf(“ FACE ”)); this line does something like this....
1. as there is a %d format specifier, it goes after the comma ( , ) to look for the interger
2. there it found a function call that is printf("face"); , so it executes it.
3. and that printf return 4, so it comes back and prints 4 in place of that %d.
int x = printf("face");
printf("%d",x);
these two line will do the same thing. - 6 years agoHelpfull: Yes(2) No(0)
- Answer is FACE4 why because here ,we print the length of the string "FACE".So answer is FACE4 .Suppose if we write "HAI" inplace of "FACE" then the output is HAI3.
- 6 years agoHelpfull: Yes(1) No(0)
- garbage value
- 6 years agoHelpfull: Yes(1) No(1)
- FACE4 is the actual answer bcz printf function returns no.of characters in it.
- 6 years agoHelpfull: Yes(0) No(0)
- It is a valid statement.E need to know the printf properties.
First from inner printf it prints FACE
and secondly it counts the no of letters in specifier and print 4 - 6 years agoHelpfull: Yes(0) No(0)
- Printf("FACE") prin FaCE whereas %d return no. of character in prinf block
option 1 FACE$ - 6 years agoHelpfull: Yes(0) No(0)
- the correct answer is 1
coz printf statement executed from left to right so FACE is printed and then it will print 4 bcoz FACE has characters. - 6 years agoHelpfull: Yes(0) No(0)
- Option 1 because first printf prints face then count the no of digits that is 4 ans face4
- 6 years agoHelpfull: Yes(0) No(0)
- Face4 is correct answer bcoz face+no of words=face4
- 6 years agoHelpfull: Yes(0) No(0)
- As per function printf () returns legth automatically thus first printed Face and then after second printf() prints length as per int parameter.
- 6 years agoHelpfull: Yes(0) No(0)
- Evaluate from right to left so it prints FACE4
- 6 years agoHelpfull: Yes(0) No(0)
- FACE4 is the answer.
- 6 years agoHelpfull: Yes(0) No(1)
- printf gives FACE and its size is 4 so intiial printf returns its size
so ans is FACE4 - 6 years agoHelpfull: Yes(0) No(0)
- FACE4 beacause that 1st printf print the face and the 2nd will print the no of character in string
- 5 years agoHelpfull: Yes(0) No(0)
- face4 because first it will print face and second acess specifier is d which read how many character are there
- 5 years agoHelpfull: Yes(0) No(0)
- 1
FACE4(FACE is printed first then as printf return integer value it returns 4 length of FACE) - 5 years agoHelpfull: Yes(0) No(1)
- 1
Because it is inside print statement that will be print same what in that out side print of is prints number of characters - 5 years agoHelpfull: Yes(0) No(0)
- ans is FACE4
- 5 years agoHelpfull: Yes(0) No(0)
- face4 is the ans because always inner print if is printed first and then printf is given%d so it prints int value
- 5 years agoHelpfull: Yes(0) No(0)
TCS Other Question