Playground

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

初始化代码区

Caution

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

#include <iostream>
using namespace std;

cout.setf(ios::boolalpha);
cout << "初始化完成!" << endl;

试验代码区

Note

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

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

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

算术运算

// 算术运算
cout << (10 % 3) << endl;
cout << (10 % -3) << endl;
cout << (-10 % 3) << endl;
cout << (-10 % -3) << endl;
cout << (10 / 3) << endl;
cout << (10 / -3) << endl;
cout << (-10 / 3) << endl;
cout << (-10 / -3) << endl;
cout << (10 / 3 * 3) << endl;

关系运算

// 关系运算
cout << ('A' < 'a') << endl;
cout << (true < false) << endl;

位运算

// 位运算
cout << (0x73 & 0x01) << endl; // 0x73 == 0b 0111 0011
cout << (0x01 | 0x0F) << endl;
cout << (0x03 ^ 0x01) << endl;
cout << (0x01 << 4) << endl;
cout << (0x0F >> 2) << endl;

逻辑运算

// 逻辑运算
bool t = true, f = false;
cout << (t and f) << endl;
cout << (t or f) << endl;
cout << (not f) << endl;

赋值运算

// 赋值运算
int a = 0;
cout << (a = 1) << endl;
cout << (a = a + 1) << endl;
cout << (a += 1) << endl;
cout << (a *= 2) << endl;
cout << (a /= 2) << endl;
cout << (a %= 2) << endl;
cout << a << endl;

自增/自减运算

// 自增/自减运算
int b = 0;
cout << (b++) << endl;
cout << (++b) << endl;
cout << (b--) << endl;
cout << (--b) << endl;
cout << b << endl;

条件运算

// 条件运算
int c = 2;
cout << (c > 0? (c -= 1) : (c += 1)) << endl;
cout << c << endl;

逗号运算

// 逗号运算
int d = 0, e = 0;
cout << (d++, e+2, e--) << endl;
cout << d << ' ' << e << endl;

逻辑表达式短路

// 逻辑表达式短路
int f = 0;
cout << ((f = 0) and (f = 1)) << endl;
cout << f << endl;
cout << ((f = 1) or (f = 0)) << endl;
cout << f << endl;