+ 1

What is the use of f in printf ?

24th Jan 2021, 5:23 PM
Amber Tripathi
Amber Tripathi - avatar
6 Réponses
+ 5
You mean the 'f' in the function *name* 'printf'? 'Formatted' most probably because printf *formats* the string you pass and then prints it.
24th Jan 2021, 5:30 PM
XXX
XXX - avatar
+ 3
Padala Vamsi I think he was trying to ask what is the *significance* of the 'f' in the name printf. Because that 'f' must mean something right? You don't name a function that adds 2 numbers 'peanuts'. Amber Tripathi what are you trying to ask? Are you asking why there is a 'f' in printf and why it is not just 'print' or are you asking what does the %f format specifier mean. To amswer the latter, it means you want to print a floating point number.
24th Jan 2021, 6:19 PM
XXX
XXX - avatar
+ 3
XXX your first answer is right I google it 👍 actually a interviewer asked me the same question what is the work of f in printf
24th Jan 2021, 6:37 PM
Amber Tripathi
Amber Tripathi - avatar
+ 2
So what is the working of %d %c %f etc I think they are also format specifier
24th Jan 2021, 5:33 PM
Amber Tripathi
Amber Tripathi - avatar
+ 2
I think you misunderstood the concept 'f' in the name of printf has nothing to do with formatting. It doesn't do formatting, only the format specifiers are used to format string. The 'f' in the printf is just a part of name. That means who so ever created printf function has kept that name, if some other person creates exact function he can name anything like print or print_string or print_format_string etc.,
24th Jan 2021, 5:56 PM
Padala Vamsi
Padala Vamsi - avatar
+ 2
Try to put in c program print("Hello world"); it throws an error because there is no function in c by default with name print. There is printf by default. So, string is not getting format because of 'f' in name printf.
24th Jan 2021, 6:11 PM
Padala Vamsi
Padala Vamsi - avatar