C Format Specifiers
सी फॉर्मैट स्पेसिफायर्स
In C programming, format specifiers are used in functions like printf()
and scanf()
to specify the type of data being handled.
C programming में format specifiers का उपयोग printf()
और scanf()
जैसे functions में data के प्रकार को specify करने के लिए किया जाता है।
Integer (%d)
#include <stdio.h>
int main() {
int num = 10;
printf("Integer: %d", num);
return 0;
}
Explanation (English): The %d specifier is used to print integer values.
व्याख्या (हिंदी): %d specifier का उपयोग integer मान दिखाने के लिए होता है।
Output:
Integer: 10
Float (%f)
#include <stdio.h>
int main() {
float price = 15.50;
printf("Float: %.2f", price);
return 0;
}
Explanation (English): The %f specifier is used to print floating-point numbers.
व्याख्या (हिंदी): %f specifier दशमलव संख्या दिखाने के लिए होता है।
Output:
Float: 15.50
Character (%c)
#include <stdio.h>
int main() {
char ch = 'A';
printf("Character: %c", ch);
return 0;
}
Explanation (English): The %c specifier prints a single character.
व्याख्या (हिंदी): %c specifier एक अक्षर दिखाने के लिए होता है।
Output:
Character: A
String (%s)
#include <stdio.h>
int main() {
char str[] = "Hello";
printf("String: %s", str);
return 0;
}
Explanation (English): The %s specifier prints a string of characters.
व्याख्या (हिंदी): %s specifier स्ट्रिंग दिखाने के लिए होता है।
Output:
String: Hello
Unsigned Integer (%u)
#include <stdio.h>
int main() {
unsigned int u = 4000;
printf("Unsigned int: %u", u);
return 0;
}
Explanation (English): %u specifier prints unsigned (positive) integers.
व्याख्या (हिंदी): %u specifier unsigned integers दिखाने के लिए होता है।
Output:
Unsigned int: 4000
Hexadecimal (%x / %X)
#include <stdio.h>
int main() {
int num = 255;
printf("Hex lowercase: %x\n", num);
printf("Hex uppercase: %X", num);
return 0;
}
Explanation (English): %x and %X print hexadecimal values in lowercase and uppercase respectively.
व्याख्या (हिंदी): %x और %X hexadecimal को lowercase और uppercase में दिखाते हैं।
Output:
Hex lowercase: ff
Hex uppercase: FF