In C printf(), %n is a special format specifier which instead of printing something causes printf() to load the variable pointed by the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n.
The above program prints “geeks for geeks 10”. The first printf() prints “geeks for geeks”. The second printf() prints 10 as there are 10 characters printed (the 10 characters are “geeks for “) before %n in first printf() and c is set to 10 by first printf().
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Nested printf (printf inside printf) in C
- Use of & in scanf() but not in printf()
- How to print % using printf()?
- Execution of printf with ++ operators
- Cin-Cout vs Scanf-Printf
- Passing NULL to printf in C
- How to change the output of printf() in main() ?
- puts() vs printf() for printing a string
- Return values of printf() and scanf() in C/C++
- What is the difference between printf, sprintf and fprintf?
- Format specifiers in different Programming Languages
- C program to find square root of a given number
- C program to print odd line contents of a File followed by even line content
- Getting System and Process Information Using C Programming and Shell in Linux