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.
- Difference between %d and %i format specifier in C language
- Problem with scanf() when there is fgets()/gets()/scanf() after it
- Operators in C | Set 1 (Arithmetic Operators)
- Difference between getc(), getchar(), getch() and getche()
- What is the difference between printf, sprintf and fprintf?
- Bitwise Operators in C/C++
- To find sum of two numbers without using any operator
- Scansets in C
- puts() vs printf() for printing a string
- Initialization of data members
- "delete this" in C++
- gets() is risky to use!
- What is return type of getchar(), fgetc() and getc() ?
- Return values of printf() and scanf() in C/C++
- How to print % using printf()?