C语言完美演绎4-2

/* 范例:4-2 */

#include <stdio.h>

void main()

{

char *str = "null-terminator string";

int count; /* 记录%n前一字符输出位置(即输出字符数) */

int ComputerAddr; /* 计算机用的地址格式 */

/* Integer type */

printf("signed int(-20)\n");

printf("%%d:%d %%i:%i\n",-20,-20); /* 所有%%都只单纯输出%字符 */

printf("unsigned int(20)\n");

printf("%%o:%o %%u:%u %%x:%x %%X:%X\n",20,20,20,20);

/* Floating point type */

/* 0.0000456 = 4560e-8 但输出数因格式化符号f,e,g,E,G而不同 */

printf("Floating point(0.0000456(4560e-8))\n"); /* #1 */

printf("%%f:%f %%e:%e %%g:%g %%E:%E %%G:%G\n", \

4560e-8,0.0000456,4560e-8,0.0000456,4560e-8);

/* char (null string)type */

printf("char, char* string\n");

printf("%%c:%c %%s:%s\n",'A',str);

/* %n 前一字符输出位置(即输出字符数) */

printf("%%n前一字符输出位置(即输出字符数)\n");

printf("123%d %n\n",456,&count); /* 输出字符数存到&Count地址 */

printf("%d\n",count); /* #2 */

/* %p 计算机用的地址系统 */ /* #3 */

printf("%%p计算机用的地址格式\n");

printf("Address System: %p\n",&ComputerAddr);

getchar();

}

程序执行结果:

signed int(-20)

%d:-20 %i:-20

unsigned int(20)

%o:24 %u:20 %x:14 %X:14

Floating point(0.0000456(4560e-8))

%f:0.000046 %e:4.560000e-05 %g:4.56e-05 %E:4.560000E-05 %G:4.56E-05

char, char* string

%c:A %s:null-terminator string

%n前一字符输出位置(即输出字符数)

123456

7

%p计算机用的地址格式

Address System: 0064FDF8

相关推荐
麻瓜老宋2 小时前
AI开发C语言应用按步走,表达式计算器calc的第二十二步,分号赋值链式修复、TOKEN_ASSIGN
c语言·开发语言·atomcode
SilentSlot6 小时前
【C/C++】手写 DPDK 协议栈(十一):基于 PPS、SYN 比例和源 IP 熵的 DDoS 检测
c语言·c++·tcp/ip
冻柠檬飞冰走茶8 小时前
PTA基础编程题目集 7-15 计算圆周率(C语言实现)
c语言·开发语言·数据结构·算法
Rabitebla11 小时前
C++ 内存管理全面复习:从内存分布到 operator new/delete
java·c语言·开发语言·c++·算法·leetcode
SilentSlot11 小时前
【C/C++】手写 DPDK 协议栈(八):用五元组 Hash 加速连接定位
c语言·c++·哈希算法
Tisfy12 小时前
LeetCode 3517.最小回文排列 I:排序(Python两行版) / 计数(O(n)时间+O(C)空间+字符串原地修改)
c语言·python·leetcode·字符串·排序·计数排序·回文
菜鸟的升级路12 小时前
C语言栈刷题:LeetCode 20 有效的括号完整解题笔记
c语言·笔记·leetcode
冻柠檬飞冰走茶12 小时前
PTA基础编程题目集 7-13 日K蜡烛图(C语言实现)
c语言·开发语言·数据结构·算法
SilentSlot14 小时前
【C/C++】手写 DPDK 协议栈(十二):TCP 并发与自实现 epoll 的就绪事件分发
c语言·c++·tcp/ip
SilentSlot14 小时前
【C/C++】手写 DPDK 协议栈(六):TCP 三次握手、状态机与数据回显
c语言·c++·tcp/ip