无
不同整型数据类型在内存中占多大(字节),具体格式详见输出样例,输出样例中的?为不同整型数据类型在内存中占的字节数。输出样例如下:
The size of short is ? bytes.
The size of int is ? bytes.
The size of long is ? bytes.
The size of long long is ? bytes.
public class Main {
public static void main(String[] args){
//bytes方法已自动除完8,不同于.size()方法还需要手动除以
System.out.println("The size of short is "+ Short.BYTES +" bytes.");
System.out.println("The size of int is "+ Integer.BYTES +" bytes.");
System.out.println("The size of long is "+ Long.BYTES +" bytes.");
System.out.println("The size of long long is "+ Long.BYTES +" bytes.");
}
} Java中没有long long
/**
*
* @Title 有容乃大
* @Description 确定不同整型数据类型在内存中占多大(字节),输出不同整型数据类型在内存中占多大(字节)。
*
* @author weijunfu<ijunfu @ qq.com>
* @date 2022/03/17 23:50
* @version 1.0.0
*
*/
public class Main {
public static void main(String[] args) {
System.out.printf("The size of short is %d bytes.\n", Short.BYTES);
System.out.printf("The size of int is %d bytes.\n", Integer.BYTES);
System.out.printf("The size of long is %d bytes.\n", Long.BYTES);
System.out.printf("The size of long long is %d bytes.\n", Long.BYTES);
}
}
#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.\n",sizeof(long long));
return 0;
} #include<stdio.h>
int main()
{
int a,b,c,d;
a=sizeof(short);
b=sizeof(int);
c=sizeof(long);
d=sizeof(_int64);
printf("The size of short is %d bytes.\n",a);
printf("The size of int is %d bytes.\n",b);
printf("The size of long is %d bytes.\n",c);
printf("The size of long long is %d bytes.",d);
return 0;
}