C Format Specifiers
Learn how to use printf format specifiers like %d, %f, %c, %s and more with examples.
C में printf के format specifiers जैसे %d, %f, %c, %s आदि को उदाहरणों के साथ समझें।
Example 1: Integer (%d)
#include <stdio.h>
int main() {
int a = 10; printf("%d", a);
return 0;
}
Prints integer value.
Integer value print करता है।
Output: 10
Example 2: Float (%f)
#include <stdio.h>
int main() {
float b = 3.14; printf("%f", b);
return 0;
}
Prints float (decimal) value.
Decimal (float) value print करता है।
Output: 3.140000
Example 3: Float (2 decimal) (%.2f)
#include <stdio.h>
int main() {
float pi = 3.1415; printf("%.2f", pi);
return 0;
}
Prints float with 2 decimals.
2 दशमलव तक float print करता है।
Output: 3.14
Example 4: Character (%c)
#include <stdio.h>
int main() {
char ch = 'A'; printf("%c", ch);
return 0;
}
Prints a single character.
एक अक्षर print करता है।
Output: A
Example 5: String (%s)
#include <stdio.h>
int main() {
char str[] = "Hello"; printf("%s", str);
return 0;
}
Prints a string.
String print करता है।
Output: Hello
Example 6: Unsigned int (%u)
#include <stdio.h>
int main() {
unsigned int x = 25; printf("%u", x);
return 0;
}
Prints unsigned integer.
Unsigned integer print करता है।
Output: 25
Example 7: Long int (%ld)
#include <stdio.h>
int main() {
long int y = 100000L; printf("%ld", y);
return 0;
}
Prints long integer.
लंबा integer value print करता है।
Output: 100000
Example 8: Unsigned long (%lu)
#include <stdio.h>
int main() {
unsigned long z = 4294967295; printf("%lu", z);
return 0;
}
Prints unsigned long.
Unsigned long value print करता है।
Output: 4294967295
Example 9: Double (%lf)
#include <stdio.h>
int main() {
double d = 9.81; printf("%lf", d);
return 0;
}
Prints double value.
Double value print करता है।
Output: 9.810000
Example 10: Scientific (%e)
#include <stdio.h>
int main() {
float e = 12345.678; printf("%e", e);
return 0;
}
Prints in scientific notation.
Scientific format में print करता है।
Output: 1.234568e+04
Example 11: Hexadecimal (%x)
#include <stdio.h>
int main() {
int h = 255; printf("%x", h);
return 0;
}
Prints value in hexadecimal.
Hexadecimal में print करता है।
Output: ff
Example 12: Octal (%o)
#include <stdio.h>
int main() {
int o = 10; printf("%o", o);
return 0;
}
Prints value in octal.
Octal (base 8) में print करता है।
Output: 12
Example 13: Percent Sign (%%)
#include <stdio.h>
int main() {
printf("100%% Complete");
return 0;
}
Prints percentage symbol.
Percent symbol print करता है।
Output: 100% Complete
Example 14: Pointer address (%p)
#include <stdio.h>
int main() {
int a = 5; printf("%p", &a);
return 0;
}
Prints memory address.
Variable का address print करता है।
Output: 0x....
Example 15: Characters written (%n)
#include <stdio.h>
int main() {
int n; printf("Hello%n", &n); printf("\nCount: %d", n);
return 0;
}
Stores character count printed so far.
अब तक print हुए characters की संख्या store करता है।
Output: Hello
Count: 5