user6883777 user6883777 - 1 month ago 6
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