惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - Neo0820

把阿里云效制品仓库当成Maven私仓推送私包 CentOS 空环境安装容器 容器docker系列 docker容器 从windows迁移到centos docker 容器container 镜像image 删除常用备忘 dbsyncer注意事项 博文阅读密码验证 - 博客园 pingcode 代码关联规则 博文阅读密码验证 - 博客园 lilishop 锁 威纶通屏幕(HMI)数据地址格式的讲解 西门子S7-200的VB、VW和VD 字节地址和位地址有什么区别? 西门子plc s7-200 中I、Q、M、SM、T、C、V、S、L分别指什么? 博文阅读密码验证 - 博客园 威纶通HMI常见数据格式 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 威纶通HMI系列
C语言各数据类型所占字节数
Neo0820 · 2022-12-20 · via 博客园 - Neo0820

编写C程序时需要考虑每种数据类型在内存中所占的内存大小,即使同一种数据类型在不同平台下所占内存大小亦不相同。为了得到某个类型在特定平台上的准确大写,可以使用sizeof运算符,表达式sizeof(type)得到对象或类型的存储字节大小

#include <stdio.h>
#include <stdlib.h>
#include <float.h>

int main(void)
{
    printf("数据类型:char,存储大小:%d字节、最小值:%hhd,最大值:%hhd\n",
                sizeof(char), CHAR_MIN, CHAR_MAX);
    printf("数据类型:unsigned char,存储大小:%d字节、最小值:%hhu,最大值:%hhu\n",
                sizeof(unsigned char), 0U, UCHAR_MAX);
    printf("数据类型:short,存储大小:%d字节、最小值:%hd,最大值:%hd\n",
                sizeof(short), SHRT_MIN, SHRT_MAX);
    printf("数据类型:unsigned short,存储大小:%d字节、最小值:%hu,最大值:%hu\n",
                sizeof(unsigned short), 0U, USHRT_MAX);
    printf("数据类型:int,存储大小:%d字节、最小值:%d,最大值:%d\n",
                sizeof(int), INT_MIN, INT_MAX);
    printf("数据类型:unsigned int,存储大小:%d字节、最小值:%u,最大值:%u\n",
                sizeof(unsigned int), 0U, UINT_MAX);
    printf("数据类型:long,存储大小:%d字节、最小值:%ld,最大值:%ld\n",
                sizeof(long), LONG_MIN, LONG_MAX);
    printf("数据类型:unsigned long,存储大小:%d字节、最小值:%lu,最大值:%lu\n",
                sizeof(unsigned long), 0LU, ULONG_MAX);
    printf("数据类型:float,存储大小:%d字节、最小值:%g,最大值:%g\n",
                sizeof(float), FLT_MIN, FLT_MAX);
    printf("数据类型:double,存储大小:%d字节、最小值:%lg,最大值:%lg\n",
                sizeof(double), DBL_MIN, DBL_MAX);
    printf("数据类型:long long,存储大小:%d字节、最小值:%lld,最大值:%lld\n",
                sizeof(long long), LLONG_MIN, LLONG_MAX);
    printf("数据类型:unsigned long long,存储大小:%d字节、最小值:%llu,最大值:%llu\n",
                sizeof(unsigned long long), 0LLU, ULLONG_MAX);
    printf("数据类型:long double,存储大小:%d字节、最小值:%Lg,最大值:%Lg\n",
                sizeof(long double), LDBL_MIN, LDBL_MAX);

    return EXIT_SUCCESS;
}