CPP C++ type casting

C++ type casting

  • A cast is a special operator that forces one data type to be converted into another.
  • As an operator, a cast is unary and has the same precedence as any other unary operator.

Syntax:

type-name (expression) //c++ notation 

Example:

#include <iostream>
 
main()
{
double a = 99.09399;
float b = 97.20;
int c ;
 
c = (int) a;
cout << "Line 1 - Value of (int)a is :" << c << endl ;
   
c = (int) b;
cout << "Line 2 - Value of (int)b is  :" << c << endl ;
   
return 0;
}

Output:

Line 1 - Value of (int)a is :99
Line 2 - Value of (int)b is :97

 



Share This Page to Download:

Share to Download

Share This Page on:

Question


sagar | 18-Jun-2016 10:19:08 am

Very helpful tutorials and easy to understand.....


Ask Question