type sizeof: char, short, int, long, float, double and prefix unsigned, long

简介:
C的自定义类型比较少, 占用字节数可以使用sizeof 操作符来获取.
char, short, int, long, float, double
char 实际存储为数字.占用1字节.

可使用的前缀 : unsigned, long

下面在一台64位的LINUX上得到的结果 :
[root@db-172-16-3-150 zzz]# cat n.c
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

int i;
int main() {
  fprintf(stdout, "sizeof(%s)=%lu\n", "short", sizeof(short));
  fprintf(stdout, "sizeof(%s)=%lu\n", "int", sizeof(int));
  fprintf(stdout, "sizeof(%s)=%lu\n", "char", sizeof(char));
  fprintf(stdout, "sizeof(%s)=%lu\n", "long", sizeof(long));
  fprintf(stdout, "sizeof(%s)=%lu\n", "float", sizeof(float));
  fprintf(stdout, "sizeof(%s)=%lu\n", "double", sizeof(double));
  fprintf(stdout, "sizeof(%s)=%lu\n", "long int", sizeof(long int));
  fprintf(stdout, "sizeof(%s)=%lu\n", "long long int", sizeof(long long int));
  fprintf(stdout, "sizeof(%s)=%lu\n", "long long", sizeof(long long));
  fprintf(stdout, "sizeof(%s)=%lu\n", "long double", sizeof(long double));
  return 0;
}
结果 : 
[root@db-172-16-3-150 zzz]# gcc -O3 -Wall -Wextra -Werror -g ./n.c -o n && ./n 
sizeof(short)=2
sizeof(int)=4
sizeof(char)=1
sizeof(long)=8
sizeof(float)=4
sizeof(double)=8
sizeof(long int)=8
sizeof(long long int)=8
sizeof(long long)=8
sizeof(long double)=16

目录
相关文章
|
存储 C语言
使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小
【10月更文挑战第13天】使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小。
634 1
|
Python
[oeasy]python036_数据类型有什么用_type_类型_int_str_查看帮助
本文回顾了Python中`ord()`和`chr()`函数的使用方法,强调了这两个函数互为逆运算:`ord()`通过字符找到对应的序号,`chr()`则通过序号找到对应的字符。文章详细解释了函数参数类型的重要性,即`ord()`需要字符串类型参数,而`chr()`需要整数类型参数。若参数类型错误,则会引发`TypeError`。此外,还介绍了如何使用`type()`函数查询参数类型,并通过示例展示了如何正确使用`ord()`和`chr()`进行转换。最后,强调了在函数调用时正确传递参数类型的重要性。
166 3
|
Dart JavaScript 前端开发
Dart或Flutter中解决异常-type ‘int‘ is not a subtype of type ‘double‘
Dart或Flutter中解决异常-type ‘int‘ is not a subtype of type ‘double‘
606 4
|
JSON 数据格式 Python
【python】解决json.dump(字典)时报错Object of type ‘float32‘ is not JSON serializable
在使用json.dump时遇到的“Object of type ‘float32’ is not JSON serializable”错误的方法,通过自定义一个JSON编码器类来处理NumPy类型的数据。
934 1
|
存储 C语言
计算 int, float, double 和 char 字节大小
计算 int, float, double 和 char 字节大小。
315 3
|
存储 编译器 C++
C++从遗忘到入门问题之float、double 和 long double 之间的主要区别是什么
C++从遗忘到入门问题之float、double 和 long double 之间的主要区别是什么
420 0
|
存储 SQL 数据库
MySQL设计规约问题之为何推荐用DECIMAL代替FLOAT和DOUBLE来存储精确浮点数
MySQL设计规约问题之为何推荐用DECIMAL代替FLOAT和DOUBLE来存储精确浮点数
|
存储 Python
语音输入,python数据类型,type()用来查看数据类型,数据类型转换,int(x)转整数,float(x)转换为浮点数,str(x),将对象转为字符串,标识符,标识符不允许使用关键字,关键字参考
语音输入,python数据类型,type()用来查看数据类型,数据类型转换,int(x)转整数,float(x)转换为浮点数,str(x),将对象转为字符串,标识符,标识符不允许使用关键字,关键字参考
|
存储 算法 物联网
int8与long long的深入对比与探讨
int8与long long的深入对比与探讨
|
存储 编译器 程序员
int 和 long 的区别
int 和 long 的区别