Click here to Skip to main content
15,884,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
int main() {
 unsigned long n;
 int c;
 printf( "Nhap n: " );
 scanf( "%lu%n", &n,&c );


What I have tried:

when I enter the value n = 4321, c is 4. Why is that, hope everyone can answer my question?
Posted
Updated 5-Jan-23 5:54am

Because you told it to:
What is use of %n in printf() ? - GeeksforGeeks[^]
Since n has four digits, the value of c is set to 4.
 
Share this answer
 
Because, as described in the documentation at scanf Type Field Characters | Microsoft Learn[^], the n type code returns the number of characters read.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900