小编zac*_*m64的帖子

用c ++确定数字大小

我得到十六进制数0x04030201,存储在一个充满零的数组的中间.我的代码必须以为单位确定此数字的大小.

我需要以两种不同的方式实现这一点.我的第一种方法是使用这样的sizeof()函数:

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int num[] = {0,0,0x04030201,0,0};

    cout<<"The size of the integer is "<<sizeof(num[2])*4<<" bits."<<endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的预期输出是28位(7位有效字符的4位).但我的输出给出:

The size of the integer is 16 bits.
Run Code Online (Sandbox Code Playgroud)

我的错是什么?

c++ arrays size hex integer

1
推荐指数
1
解决办法
65
查看次数

标签 统计

arrays ×1

c++ ×1

hex ×1

integer ×1

size ×1