مرجع مفيد لمحددات التحويل ومعدلاته
في هذا المنشور ، أريد إنشاء مرجع مفيد لجميع ملفاتجتحويلاتمحدداتيمكنك استخدامها بشكل شائعprintf()
وscanf()
ووظائف الإدخال / الإخراج المماثلة.
محدد | المعنى |
---|---|
%d /%i |
عدد صحيح عشري مميز |
%u |
عدد صحيح عشري بدون إشارة |
%c |
غير موقعchar |
%s |
خيط |
%p |
المؤشر في شكل سداسي عشري |
%o |
عدد صحيح ثماني بدون إشارة |
%x /%X |
رقم سداسي عشري غير موقع |
%e |
رقم الفاصلة العائمة بالتنسيق الأسي بتنسيقe الرموز |
%E |
رقم الفاصلة العائمة بالتنسيق الأسي بتنسيقE الرموز |
%f |
double رقم بتنسيق عشري |
%g /%G |
double رقم بتنسيق عشري أو تنسيق أسي بناءً على القيمة |
بالإضافة إلى تلك المحددات ، لدينا مجموعة منالصفات التعريفية.
دعنا نبدء بأرقام. باستخدام رقم بين%
ومحدد التنسيق ، يمكنك معرفة الحد الأدنى لعرض الحقل. مثال:%3d
سوف تأخذ 3 مسافات بغض النظر عن الرقم المطبوع.
هذه:
printf("%4d\n", 1);
printf("%4d\n", 12);
printf("%4d\n", 123);
printf("%4d\n", 1234);
يجب أن تطبع
1
12
123
1234If you put a dot before the digit, you are not telling the precision: the number of decimal digits. This of course applies to decimal numbers. Example:
printf("%4.2f\n", 1.0);
printf("%4.3e\n", 12.232432442);
printf("%4.1e\n", 12.232432442);
printf("%4.1f\n", 123.22);
will print:
1.00
1.223e+01
1.2e+01
123.2In addition to digits, we have 3 special letters: h
, l
and L
.
h
, used with integer numbers, indicates a short int
(for example %hd
) or a short unsigned int
(for example %hu
)
l
, used with integer numbers, indicates a long int
(for example %ld
) or a long unsigned int (for example %lu
).
L
, used with floating point numbers, indicates a long double
, for example %Lf
Download my free C Handbook
More clang tutorials:
- Introduction to the C Programming Language
- C Variables and types
- C Constants
- C Operators
- C Conditionals
- How to work with loops in C
- Introduction to C Arrays
- How to determine the length of an array in C
- Introduction to C Strings
- How to find the length of a string in C
- Introduction to C Pointers
- Looping through an array with C
- Booleans in C
- Introduction to C Functions
- How to use NULL in C
- Basic I/O concepts in C
- Double quotes vs single quotes in C
- How to return a string from a C function
- How to solve the implicitly declaring library function warning in C
- How to check a character value in C
- How to print the percentage character using `printf()` in C
- C conversion specifiers and modifiers
- How to access the command line parameters in C
- Scope of variables in C
- Can you nest functions in C?
- Static variables in C
- C Global Variables
- The typedef keyword in C
- C Enumerated Types
- C Structures
- C Header Files
- The C Preprocessor