首页 > 试题广场 >

有容乃大

[编程题]有容乃大
  • 热度指数:90845 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
确定不同整型数据类型在内存中占多大(字节),输出不同整型数据类型在内存中占多大(字节)。 

输入描述:


输出描述:
不同整型数据类型在内存中占多大(字节),具体格式详见输出样例,输出样例中的?为不同整型数据类型在内存中占的字节数。输出样例如下:
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.");
        
    }
}

发表于 2020-08-10 06:42:06 回复(2)
我不开心了 这题用不了python写
因为python不同于其它语言,int不区分short、int、long类型,只有一种类型int
浮点数不区分float与double类型,只有一种类型float,在python中float就表示double

发表于 2020-04-04 01:00:28 回复(3)
int main(void)
{
    int a,b,c,d;
    a=sizeof(short);b=sizeof(int);c=sizeof(long);d = sizeof(long long);
    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.\n",d);
}
发表于 2020-03-12 14:20:58 回复(3)
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cout<<"The size of short is "<<sizeof(short)<<" bytes."<<endl;
    cout<<"The size of int is "<<sizeof(int)<<" bytes."<<endl;
    cout<<"The size of long is "<<sizeof(long)<<" bytes."<<endl;
    cout<<"The size of long long is "<<sizeof(long long)<<" bytes."<<endl;
    return 0;
    
}
发表于 2020-03-09 17:00:48 回复(2)
#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;
}
发表于 2021-12-16 16:16:03 回复(0)
table = {'short':2,'int':4,'long':8,'long long':8}
for k,v in table.items():
    print(f'The size of {k} is {v} bytes.')
发表于 2021-06-10 17:27:22 回复(0)
这道题很不java
发表于 2020-03-09 11:34:45 回复(2)
#include "stdio.h"
int main()
{
    int a, b, c,d;
    a = sizeof(short);
    b = sizeof(int);
    c = sizeof(long);
    d = sizeof(long long);
    printf("The size of short is %hd 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.\n", d);
    return 0;
}
发表于 2021-09-05 16:17:09 回复(2)
//用c语言

#include <stdio.h>
 
int main(void)
{
    printf("The size of short is %hd bytes.\n", sizeof(short));
    printf("The size of int is %d bytes.\n", sizeof(int));
    printf("The size of long is %ld bytes.\n", sizeof(long));
    printf("The size of long long is %lld bytes.\n", sizeof(long long));
    return 0;
}
发表于 2021-07-17 11:14:44 回复(1)
要注意空格 输入输出 以及Long long 和long在java中一样 因为 java中没有long long.size 还有就是 1byte=8bit
发表于 2020-10-14 15:39:27 回复(0)
有一说一,这道题真的难顶。
发表于 2020-03-09 15:49:40 回复(0)

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);
    }
}
发表于 2022-03-17 23:54:26 回复(1)
#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;
}
发表于 2024-10-01 17:26:42 回复(0)
#include <stdio.h>

int main()
 {
    printf("The size of short is %zd bytes.\n",sizeof(short));
    printf("The size of int is %zd bytes.\n",sizeof(int));
    printf("The size of long is %zd bytes.\n",sizeof(long));
    printf("The size of long long is %zd bytes.\n",sizeof(long long));
 

    return 0;
}
编辑于 2023-12-26 17:28:47 回复(0)
#include <stdio.h>

int main() {
   

   printf("The size of short is %zd bytes.\n",sizeof(short));
    printf("The size of int is %zd bytes.\n",sizeof(int));
     printf("The size of long is %zd bytes.\n",sizeof(long));
      printf("The size of long long is %zd bytes.\n",sizeof(long));
    return 0;
}
编辑于 2023-12-13 15:36:44 回复(0)
那位大神可以看看我这错哪了
table={'short':2,'int':4,'long':8,'long long':8}
list=[]
list.extend(table.items())
for i in list:
    print('The size of %s is %d bytes'%(i))

发表于 2023-12-06 09:26:00 回复(0)
#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;
}
发表于 2023-06-25 20:41:15 回复(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;
}

发表于 2023-06-14 17:10:40 回复(0)
#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;
}

发表于 2023-01-27 16:44:05 回复(0)
#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;
}
发表于 2022-03-14 21:20:53 回复(0)