1 条题解
-
0
练15.1 其他数据类型存储空间大小
解题思路
声明 bool 和 char 变量,依次输出 sizeof。
正确性说明
sizeof 返回变量所占字节数,符合题意。
易错点
顺序是 bool 在前、char 在后。
复杂度
本题输入规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); bool a; char b; cout << sizeof(a) << " " << sizeof(b) << "\n"; return 0; }
- 1