标签:
1.打印short、long、long long和unsigned
#include <stdio.h> int main(void) { unsigned int un = 3000000000; short end = 200; long big = 65537; long long verybig = 12345678908642; printf("un = %u and not %d\n", un, un); //u=ud printf("end = %hd and %d\n", end, end); printf("big = %ld and not %hd\n", big, big); printf("verybig=%lld and not %ld\n", verybig, verybig); return 0; }
结论:即使是变量本身是无符号类型, 打印的时候也需要加上u, 否则按有符号类型打印; 如果用短类型去打印长类型, 则会被截取最后N位
2.八进制或十六进制表示一个字符
char c = ‘\0101‘; char ch = ‘\x41‘;
PS:为什么使用‘\0101‘而不是0101表示一个字符, 因为‘\0101‘更能清晰的表达一个字符的意图, 其次‘\0101‘这样的转义序列可以嵌入到C字符串中, 如"Hello!\0101\n"
3.
标签:
原文地址:http://www.cnblogs.com/JohnABC/p/4462157.html