Hard
Reading a float through an int*
Compiled with optimizations enabled (e.g. -O2), what does this program most likely print?
main.cpp
#include <iostream>
int bumpAndRead(float* f, int* i) {
*i = 0; // (1) write through int*
*f = 3.14f; // (2) write through float* to the SAME address
return *i; // (3) re-read through int*
}
int main() {
float value = 1.0f;
int* asInt = reinterpret_cast<int*>(&value); // (4) unrelated-type alias
std::cout << bumpAndRead(&value, asInt) << std::endl;
}65 of 117 in C++