磕代码:输出不同整型数据类型在内存中占多大(字节)
2020-08-05 15:10
204 查看
c:
#include<stdio.h> int main() { printf("The size of short is %d bytes.\n",sizeof(short)); printf("The size of int is %d bytes.\n",sizeof(int)); printf("The size of long is %d bytes.\n",sizeof(long)); printf("The size of long long is %d bytes.",sizeof(long long)); return 0; }
注:字符串用双引号,字符用单引号。
C语言pirntf里用单引号会报错:数组越界。
sizeof的使用。
c++:
#include <bits/stdc++.h> using namespace std; int main() { //使用sizeof运算符输出各种类型的大小 printf("The size of short is %d bytes.\n", sizeof(short)); printf("The size of int is %d bytes.\n", sizeof(int)); printf("The size of long is %d bytes.\n", sizeof(long)); printf("The size of long long is %d bytes.\n", sizeof(long long)); }
注:也可以用printf。
Java:
public class Main{ public static void main(String[]args){ System.out.println("The size of short is "+Short.SIZE/8+" bytes."); System.out.println("The size of int is "+Integer.SIZE/8+" bytes."); System.out.println("The size of long is "+Long.SIZE/8+" bytes."); System.out.println("The size of long long is "+Long.SIZE/8+" bytes."); } }
注:SIZE大写;
求的是位数,算字节数要再除以8;
println自带换行;
long和longlong是一样的?;
相关文章推荐
- 共享内存多次写入不同类型的数据测试代码
- 第二十三节,不同数据类型在内存中的存址方式,及深浅拷贝
- Python入门(三)——(基本运算符、逻辑运算符(与C++不同)、循环语句、print函数、三引号可打印多行、格式化输出、数据类型初识、列表和元组(与C++不同)、enumerate、赋值新解读)
- c语言基本数据类型在内存中所占字节
- 黑马程序员---数据类型及内存占用字节
- 不同编译器下的各个数据类型的字节长度
- 不同数据类型在32位和64位下所占的字节的对比
- C/C++基本数据类型所占字节数及内存字节对齐
- python输出不换行(同一行输出不同类型数据)
- 各种数据类型在不同平台不同编译器所占用字节汇总
- C/C++基本数据类型占用字节数及内存字节对齐
- 让ASP.NET MVC的Controller输出不同类型数据
- Python 数据处理2(不同数据类型转列表输出)
- 基本数据类型变量 结构体 union 类的内存字节对齐
- C#基础数据类型与字节数组(内存中的数据格式)相互转换(BitConverter 类)
- 各数据类型所占的内存大小(单位:字节)
- 栈区,堆区,全局区,文字常量区,程序代码区详解(程序中不同类型数据所在区)
- 输出个数据类型的字节长度
- 看你的linux编译系统是32位还是64位最简单的方法以及不同数据类型占用字节个数
- 不同位数的操作系统数据类型所占字节