Pune, , India
DBMS, SQL Server, C Language
Understanding Printf()
Model.ProfilDetail.name
Amit Bisht 07 Jul 14   Views 27 Views  Comments 1 Comments 
This blog is to explain the behaviour of printf function used in c language. I start with basic description of printf function . printf is defined in stdio.h header file. Itis used to print something on the console screen. As mentioned printf is a function then as we know any function have a return type and the number of arguments are optional. So the question arises what is return type of function printf Syntax int printf const char format,arguments, ... So we clear now from the syntax that return type of priintf is int . Now the next question arises what does it return well discuss it later in the same blog but before it let me explain you how printf actually works. Example 1 printfHello world output Hello world Example 2 int i 10 printfPrinting value of variable i d, i output Printing value of variable i 10 Example 3 Important int i 10 printfd,d,d,i,i,i output 12,12,10 This output is because of left to right argument passing in function. I must say now you got aware about how function really works. Now iits turn to explain what a printf function returns The answer is it returns the number of character it prints. Example 4 int i printfHello world printfn Return value by above function is d,i output Hello world Return value by above function is 11. //Hello -gt 5 Blank space in between hello world -gt 1 world -gt 5 11 Note Escape sequence like n t a conted as single character. I hope this blog may help you. So please comment if it is helpfull and also correct me wherever im wrong.
    • Social Share
      for this Blog
  • Comment
    • Hello Amit Bisht, I am Navjot Kaur. This is good but i don't understand example no 3rd. So please can you explain this with more detail.

Porfolio And Blogs
Amit Bisht follows various companies, these companies and employers can view Amit's resume.
blog portfolio
Upload your resume to get best job opportunities.

Register free!