对printf函数的理解1
看如下代码:
#include <stdio.h> int main(int argc, const char *argv[]) { printf("%s\n","peng","dopmg","石家庄铁道大学"); return 0; }
将代码改成:
#include <stdio.h> int main(int argc, const char *argv[]) { printf("%s%s%s\n","peng","dopmg","石家庄铁道大学"); return 0; }
结果变成:
格式化输出:
1 #include <stdio.h> 2 #include <limits.h> 3 4 int main(void) 5 { 6 unsigned char uc = UCHAR_MAX; 7 unsigned short us = USHRT_MAX; 8 unsigned int ui = UINT_MAX; 9 unsigned long ul = ULONG_MAX; 10 unsigned long long ull = ULLONG_MAX; 11 puts("[output, specific values are implementation-dependent.]"); 12 13 printf("UCHAR_MAX, %u (decimal), %#o (octal), %#x (hex)\n", 14 uc, uc, uc); 15 16 17 printf("USHRT_MAX, %u (decimal), %#o (octal), %#x (hex)\n", 18 us, us, us); 19 20 printf("UINT_MAX, %u (decimal), %#o (octal),\n %#x (hex)\n", 21 ui, ui, ui); 22 23 printf("ULONG_MAX, %lu (decimal), %#lo (octal),\n %#lx (hex)\n", 24 ul, ul, ul); 25 26 printf 27 ("ULLONG_MAX, %llu (decimal),\n %#llo (octal),\n %#llx (hex)\n", 28 ull, ull, ull); 29 30 puts("[end of output]"); 31 return 0; 32 } 33 34 [output, specific values are implementation-dependent.] 35 UCHAR_MAX, 255 (decimal), 0377 (octal), 0xff (hex) 36 USHRT_MAX, 65535 (decimal), 0177777 (octal), 0xffff (hex) 37 UINT_MAX, 4294967295 (decimal), 037777777777 (octal), 38 0xffffffff (hex) 39 ULONG_MAX, 4294967295 (decimal), 037777777777 (octal), 40 0xffffffff (hex) 41 ULLONG_MAX, 18446744073709551615 (decimal), 42 01777777777777777777777 (octal), 43 0xffffffffffffffff (hex) 44 [end of output]
本文来自博客园,作者:摩斯电码,未经同意,禁止转载