1int main()
2{
3 short a = 2000;
4 int b;
5 b = (int)a; // c-like cast notation
6 b = int(a); // functional notation
7}
1#include <iostream>
2using namespace std;
3int main(){
4 int x = 4;
5 int y = 2;
6 cout<<"La divisione dei valori e': "<<(float)y/x<<endl;
7}
1static_cast:
2//does implicit conversions between types.
3void* data;
4pointer *pData = static_cast<pointer*>(data);
5
6const_cast:
7//this can be used to remove or add the const to a variable.
8const char* characters;
9const_cast<char*>(characters);
10
11reinterpret_cast:
12//this cast is dangerous since it turns one type directly into another.
13struct S1 { int a; } s1;
14int* p1 = reinterpret_cast<int*>(&s1);