

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of %n in printf()?
In C language, %n is a special format specifier. It cause printf() to load the variable pointed by corresponding argument. The loading is done with a value which is equal to the number of characters printed by printf() before the occurrence of %n.
Note − It does not print anything. Another printf() function is used to print the statement.
Here is an example of %n in C language,
Example
#include<stdio.h> int main() { int s; printf("The value of %ns : ", &s); printf("%d", s); getchar(); return 0; }
Output
The value of s : 13
Even if we give the value to the identifier, it will not consider the value given by us. It counts the characters used before the use of %n in the statement. It will not count %n as a character.
Here is an example if we pass the value,
Example
#include<stdio.h> int main() { int s; int m = 28; int val; printf("The value of %ns and %nm %nval : ", &s, &m, &val); printf("%d\t%d\t%d", s, m, val); return 0; }
Output
The value of s and m val : 131921
- Related Questions & Answers
- What is the use of `%p` in printf in C?
- What is the correct way to use printf to print a size_t in C/C++?
- What is the difference between printf() and cout in C++?
- How to use printf () in Android sqlite?
- What is the use of sinon.js?
- How to use formatting with printf() correctly in Java?
- What is the use of JavaScript cookies?
- What is the use of NCHAR in MySQL?
- What is the use of cin.ignore() in C++?
- What is the use of Map in JavaScript?
- What is the use of ini_set() in PHP?
- What is the use of Atomics in JavaScript?
- What is the use of window.location in javascript?
- What is the use of sentry in javascript?
- What is the use of OBJECT.assign() in javascript?
Advertisements