示例:
/**
* @brief how about plain-number? show you here.
* @author wen`xuanpei
* @email 15873152445@163.com(query for any question here)
*/
#define _CRT_SECURE_NO_WARNINGS//support c-library in Microsoft-Visual-Studio
#include <stdio.h>
static void test_negative_positive_number(){
printf("\n@%s begin:\n", __FUNCTION__);
int neg = -10, pos = 20, pos2 = +20;
printf("%d, %d, %d\n", neg, pos);
float negF = -3.14, posF = 3.14, posF2 = +3.14;
printf("%f, %f, %f\n", negF, posF);
printf("\n@%s end:\n", __FUNCTION__);
}
static void print_integer_bits(int n){
!n ? fputs("0b0", stdout) : ({print_integer_bits( ((unsigned int)n)>>1 ); putchar('0' + (n & 1) );});
}
static void test_number_carry(){
printf("\n@%s begin:\n", __FUNCTION__);
int numBin = 0b1101;//0B1101//[01]
int numOtc = 012345670;//[0-7]
int numDec = 1234567890;//[0-9]
int numHex = 0x1234abcd;//0X12345678//[0-9a-fA-F]
print_integer_bits(numBin);
printf(", %o, %d, %x"/* %X */"\n"
, numOtc, numDec, numHex );
printf("\n@%s end:\n", __FUNCTION__);
}
static void test_float_math_scientific_notation(){
printf("\n@%s begin:\n", __FUNCTION__);
float numMath = 3.14;//math notation
float numSN1 = 3.14e3;//scientific notation
float numSN2 = 3.14e+3;//scientific notation
float numSN3 = 3.14e-3;//scientific notation
printf("%f\n", numMath);
printf("%f, %f, %f\n", numSN1, numSN2, numSN3);
printf("\n@%s end:\n", __FUNCTION__);
}
int main(){
test_negative_positive_number();
test_number_carry();
test_float_math_scientific_notation();
getchar();
return 0;
}
1)编译运行
2)要点分析
1)无论是整数还是浮点数字面值,都可以选择性地加上符号
2)整数的字面值进位制很灵活,殊途同归,可以根据不同的应用场景来使用,提高可读性
3)浮点数的字面值表示分为数学法和科学计数法,为了从不同应用角度凸显浮点数的特点
尾声:
其它不明白的地方不用过于纠结,那只是在浪费时间。学得多了,回过头来看自然融贯通。