user6883777 user6883777 - 8 months ago 28
C Question

String length finding program. What does the line - printf ("%s %n", str, &l); mean in the following program?

#include <stdio.h>

int main()
char str[100];
int l;
printf("%s %n",str,&l);
return 0;


This program is for finding the length of a string.

Answer Source

USE OF %n format specifier in'C' :

Ques. What is %n in c & what did it do?

Ans. • %n is a special format specifier. • It loads the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n.


 int main()
  int a;
  printf("I am shivam %nsharma ", &a);       
  printf("%d", a);
   return 0;

output: I am shivam sharma 12

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download