/*...................Ex.2 static_cast ........................
Referance code from website : https://www.geeksforgeeks.org/static_cast-in-c-type-casting-operators/
*/
#include <iostream>
using namespace std;
int main() {
int a = 10;
char c = 'a';
// //address &c convert an int pointer *q with c-type cast. it is pass at compile time, pass at run time
// int *q = (int *)&c;
// cout<<" address &c convert an int pointer *q with c-type cast = "<<*q <<endl ;
//address &c convert an int pointer *q with static_cast pass at compile time, may fail at run time
int *q = static_cast<int*>(&c);
cout<<" address &c convert an int pointer *q with static_cast = "<<*q <<endl ;
/* run coed ./Ex2_static_cast
output error complie time
error: invalid static_cast from type ‘char*’ to type ‘int*’
int* p = static_cast<int*>(&c); */
}
/* ex3*/
// https://qastack.in.th/programming/2253168/dynamic-cast-and-static-cast-in-c
#include <iostream>
#include <string>
using namespace std;
class B {};
class D : public B {};
class X {};
int main()
{
D* d = new D;
B* b = static_cast<B*>(d); // this works
cout<< b<<endl;
// X* x = static_cast<X*>(d); // ERROR - Won't compile
return 0;
}