日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C 语言printf打印各种数据类型的方法(u8/s8/u16/s16.../u64/double/float)(全)

發(fā)布時(shí)間:2023/12/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C 语言printf打印各种数据类型的方法(u8/s8/u16/s16.../u64/double/float)(全) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

首先必須知道u8,s8等數(shù)據(jù)類型的定義:

typedef signed char s8; typedef unsigned char u8; typedef signed short s16; typedef unsigned short u16; typedef signed int s32; typedef unsigned int u32; typedef signed long long s64; typedef unsigned long long u64;

與體系結(jié)構(gòu)相關(guān)的,定義在include/linux/type.h文件中:

/* bsd */ typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long;/* sysv */ typedef unsigned char unchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong;#ifndef __BIT_TYPES_DEFINED__ #define __BIT_TYPES_DEFINED__typedef __u8 u_int8_t; typedef __s8 int8_t; typedef __u16 u_int16_t; typedef __s16 int16_t; typedef __u32 u_int32_t; typedef __s32 int32_t;#endif /* !(__BIT_TYPES_DEFINED__) */typedef __u8 uint8_t; typedef __u16 uint16_t; typedef __u32 uint32_t;#if defined(__GNUC__) typedef __u64 uint64_t; typedef __u64 u_int64_t; typedef __s64 int64_t;

對于各種數(shù)據(jù)類型的打印方式總結(jié)如下如下:

數(shù)據(jù)類型打印格式
u8%d
s8%d
u16%d or %hu
s16%d or %hd
u32%u
s32%d
u64%llu
s64%lld
int%d
unsigned int%u
short int%d or %hd
long%ld
unsigned long%lu
long long%lld
unsigned long long%llu
char%c
char *%s
bool (#define stdbool.h)%d
unsigned int/int------>十六進(jìn)制%0x
unsigned long/long---->十六進(jìn)制%0lx
long long/unsigned long long ----->十六進(jìn)制%0llx
unsigned int/int------>八進(jìn)制%0o
unsigned long/long---->八進(jìn)制%0lo
long long/unsigned long long ----->八進(jìn)制%0llo
float%f
double%f or %lf
科學(xué)技術(shù)類型(必須轉(zhuǎn)化為double類型)%e
限制輸出字段寬度%x.yf (x:整數(shù)長度,y:小數(shù)點(diǎn)長度)

待解問題,在linux kernel里面也有使用bool來定義變量,查看code,定義如下:

typedef _Bool bool;

但是并沒有真正找到具體定義在何處,待解。下面是stdbool.h的source code:

#define _STDBOOL_H#ifndef __cplusplus#define bool _Bool #define true 1 #define false 0#else /* __cplusplus *//* Supporting _Bool in C++ is a GCC extension. */ #define _Bool bool#if __cplusplus < 201103L /* Defining these macros in C++98 is a GCC extension. */ #define bool bool #define false false #define true true #endif#endif /* __cplusplus *//* Signal that all the definitions are present. */ #define __bool_true_false_are_defined 1#endif /* stdbool.h */

也大致解釋了linux kernel bool type了。
如果大家有興趣,可以掃碼關(guān)注我的個(gè)人公眾號(hào):

總結(jié)

以上是生活随笔為你收集整理的C 语言printf打印各种数据类型的方法(u8/s8/u16/s16.../u64/double/float)(全)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。