Playground

在这里尽情试验你的代码!

初始化代码区

Caution

初始化代码区域主要用于引入头文件,此代码区域不可编辑。

#include <iostream>
#include <iomanip>
using namespace std;

试验代码区

Note

点击页面右上角Active按钮,等待按钮下方状态信息显示

Status:Kernel Connected kernel thebe.ipynb status changed to ready[idle]

即可编辑试验代码区的代码。编辑完成后请点击run all钮执行代码。

查看C++基础数据类型的长度和对齐:

void primitiveTypeSizeAlign() {
  cout << setw(12) << "" << setw(8) << "size" << setw(8) << "align" << '\n';
  cout << setw(12) << "bool" << setw(8) << sizeof(bool) <<setw(8) << alignof(bool) << '\n';
  cout << setw(12) << "char" << setw(8) << sizeof(char) <<setw(8) << alignof(char) << '\n';
  cout << setw(12) << "short" << setw(8) << sizeof(short) <<setw(8) << alignof(short) << '\n';
  cout << setw(12) << "int" << setw(8) << sizeof(int) <<setw(8) << alignof(int) << '\n';
  cout << setw(12) << "long" << setw(8) << sizeof(long) <<setw(8) << alignof(long) << '\n';
  cout << setw(12) << "long long" << setw(8) << sizeof(long long) <<setw(8) << alignof(long long) << '\n';
  cout << setw(12) << "float" << setw(8) << sizeof(float) <<setw(8) << alignof(float) << '\n';
  cout << setw(12) << "double" << setw(8) << sizeof(double) <<setw(8) << alignof(double) << '\n';
  cout << setw(12) << "long double" << setw(8) << sizeof(long double) <<setw(8) << alignof(long double) << '\n';
}

primitiveTypeSizeAlign();