记录一个神秘好玩 UB说不定通信题可以搞事情?。
C++ 函数的栈是可能被复用的。这听起来像句废话,但是这也代表了(在不考虑这是 UB 的前提下)刻意的地址对齐可以访问到此前的变量。
有点抽象?这个是 A+B 的代码:
#include <bits/stdc++.h>
using namespace std;
void read() {
int a, b;
cin >> a >> b;
}
void add() {
int a, b;
cout << a + b << '\n';
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
read(), add();
return cout << flush, 0;
}以上。