c++ casting code example
Example 1: casting C++
int main()
{
short a = 2000;
int b;
b = (int)a;
b = int(a);
}
Example 2: c++ casting
static_cast<int>(some_double);
Example 3: cast c++
#include <iostream>
using namespace std;
int main(){
int x = 4;
int y = 2;
cout<<"La divisione dei valori e': "<<(float)y/x<<endl;
}
Example 4: c++ casting
static_cast:
void* data;
pointer *pData = static_cast<pointer*>(data);
const_cast:
const char* characters;
const_cast<char*>(characters);
reinterpret_cast:
struct S1 { int a; } s1;
int* p1 = reinterpret_cast<int*>(&s1);