1int main()
2{
3 int a=20 , b= 25 , c= 19;
4 int sum = a + b + c;
5 float ave = (float) sum / 3; //this is called type casting (float) sum
6 cout<<"Average is : "<<ave<<endl;
7 return 0;
8}
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}
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);