blogger Indonesia

Follow judhyns blog

The printf Function


printf

Introduction

printf is used to display information on screen, that is, standard output. printf is a function that returns the number of characters printed by the printf function.

Program

#include  main() { int i = 0; i=printf("abcde");    // A printf("total characters printed %d\n",i);  //B } 

Explanation

  1. Here, five characters are printed by statement A. So, i will get the value 5.

  2. Statement B prints the value of i as 5.

  3. The general format for the printf statement has a first string argument followed by any additional arguments.

  4. In statement B, "total characters printed %d\n" is the first string argument.

  5. i is the second argument. You may have multiple arguments, but that depends on what value you have to print. For each additional argument you will have to include a placeholder. Each placeholder begins with %. In statement B, %d is the placeholder.

  6. For the second argument i, the placeholder is %d. So when you need an integer value, you have to use %d. The placeholders are given for each data type.

  7. For example, if you want to print i and j, you may have to use two placeholders. Any material in the first string argument, other than the placeholder and characters, represents the escape sequence. In this example, the escape sequence character is \n, which is not printed but acts as a directive. For example, the \n directive indicates that the next printing should be done on a new line.

Points to Remember

  1. printf is used to direct output to standard output format.

  2. printf is a function that returns the number of characters printed.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |