Posts

Showing posts from May, 2022

[15 May] Predict the output

[1]  #include <iostream> using namespace std; int main() {     int a = 10;     char c = 'a';       // pass at compile time, may fail at run time     int* q = (int*)&c;      int* p = static_cast<int*>(&c);     return 0; } ----------------------------------------------------------------------------------------------------------------- #include <iostream> using namespace std; class Base { }; class Derived : public Base { }; int main() {     Derived d1;     Base* b1 = (Base*)(&d1); // allowed     Base* b2 = static_cast<Base*>(&d1);       return 0; } ----------------------------------------------------------------------------------------------------------------- #include <iostream> using namespace std; class Base {     public:     void func()     {         cout<<"...