赞
踩
1、输出整数:%d
- int a = 10;
- printf("%d\n",a);
2、输出无符号数:%u
- unsigned int b = 25;
- printf("%u\n",b);
3、输出十六进制数:%x
- int hex = 0x25;
- printf("%x\n",hex);
4、输出指针指向的地址:%p
- int a = 0x12345678;
- int *p = &a;
- printf("%p\n",p);
5、输出字符串:%s
- //char str[] = "abcde";
- char *str = "abcde";
- printf("%s\n",str);
6、输出单个字符:%c
- char c = '1';
- printf("%c\n",c);
7、输出二进制格式
- void print_bin(int number){
- int bit = sizeof(int)*8;
- int i;
- for(i = bit - 1;i >= 0;i--){
- int bin = (number & (1 << i)) >> i;
- printf("%d", bin);
- }
- printf("\n");
- }
- int main(void){
-
- unsigned int b = 5;
- print_bin(b);
- return 0;
- }
输出二进制需要用到自定义函数,效果如图
8、输出二进制无符号格式
- /*输出二进制无符号数*/
- void print_bin(unsigned int number){
- unsigned int bit = sizeof(unsigned int)*8;
- int i;
- for(i = bit - 1;i >= 0;i--){
- unsigned int bin = (number & (1 << i)) >> i;
- printf("%u", bin);
- }
- printf("\n");
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。