c语言双精度的格式说明符_C中的格式说明符

c语言双精度的格式说明符

Format specifiers define the type of data to be printed on standard output. You need to use format specifiers whether you're printing formatted output with printf() or  accepting input with scanf().

格式说明符定义了要在标准输出上打印的数据类型。 无论是使用printf()打印格式化输出还是使用scanf()接受输入,都需要使用格式说明符。

Some of the % specifiers that you can use in ANSI C are as follows:

可以在ANSI C中使用的某些%说明符如下:

SpecifierUsed For
%ca single character
%sa string
%hishort (signed)
%hushort (unsigned)
%Lflong double
%nprints nothing
%da decimal integer (assumes base 10)
%ia decimal integer (detects the base automatically)
%oan octal (base 8) integer
%xa hexadecimal (base 16) integer
%pan address (or pointer)
%fa floating point number for floats
%uint unsigned decimal
%ea floating point number in scientific notation
%Ea floating point number in scientific notation
%%the % symbol
说明符 用于
%C 一个字符
%s 一个字符串
%hi 短(签名)
%hu 短(无符号)
%如果 长双
%n 什么都不打印
%d 十进制整数(假设以10为底)
%一世 十进制整数(自动检测底数)
%o 八进制(以8为底)整数
%X 十六进制(以16为底)整数
%p 地址(或指针)
%F 浮点数的浮点数
%u int无符号十进制
%e 科学计数法中的浮点数
%E 科学计数法中的浮点数
%% %符号

例子: (Examples:)

%c单字符格式说明符: (%c single character format specifier:)

#include <stdio.h> 

int main() { 
  char first_ch = 'f'; 
  printf("%c\n", first_ch); 
  return 0; 
}

Output:

输出:

f

%s字符串格式说明符: (%s string format specifier:)

#include <stdio.h> 

int main() { 
  char str[] = "freeCodeCamp"; 
  printf("%s\n", str); 
  return 0; 
}

Output:

输出:

freeCodeCamp

使用%c格式说明符输入字符: (Character input with the %c format specifier:)

#include <stdio.h> 

int main() { 
  char user_ch; 
  scanf("%c", &user_ch); // user inputs Y
  printf("%c\n", user_ch); 
  return 0; 
}

Output:

输出:

Y

带有%s格式说明符的字符串输入: (String input with the %s format specifier:)

#include <stdio.h> 

int main() { 
  char user_str[20]; 
  scanf("%s", user_str); // user inputs fCC
  printf("%s\n", user_str); 
  return 0; 
}

Output:

输出:

fCC

%d%i十进制整数格式说明符: (%d and %i decimal integer format specifiers:)

#include <stdio.h> 

int main() { 
  int found = 2015, curr = 2020; 
  printf("%d\n", found); 
  printf("%i\n", curr); 
  return 0; 
}

Output:

输出:

2015
2020

%f%e浮点数格式说明符: (%f and %e floating point number format specifiers:)

#include <stdio.h>

int main() { 
  float num = 19.99; 
  printf("%f\n", num); 
  printf("%e\n", num); 
  return 0; 
}

Output:

输出:

19.990000
1.999000e+01

%o八进制整数格式说明符: (%o octal integer format specifier:)

#include <stdio.h> 

int main() { 
  int num = 31; 
  printf("%o\n", num); 
  return 0; 
}

Output:

输出:

37

%x十六进制整数格式说明符: (%x hexadecimal integer format specifier:)

#include <stdio.h> 

int main() { 
  int c = 28; 
  printf("%x\n", c); 
  return 0; 
}

Output:

输出:

1c

翻译自: https://www.freecodecamp.org/news/format-specifiers-in-c/

c语言双精度的格式说明符

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值