
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Explicit type casting operator in C++
A type cast provides a method for explicit conversion of the type of an object in a specific situation. It can be used as a unary expression −
( type-name ) cast-expression
The compiler treats cast-expression as type type-name after a typecast has been made. Casts are used to convert objects of any scalar kind to or from the other scalar type. Explicit type casts are constrained by the same rules that determine the effects of implicit conversions. Additional restraints on casts could result from the actual sizes or representation of specific types
example
#include using namespace std; int main() { float x = 3.1; int i; i = (int)x; cout << x << ", " << i << endl; return 0; }
Output
This will give the output −
3.1, 3
- Related Articles
- Explicit Type Casting in Python Language
- What are the differences between Widening Casting (Implicit) and Narrowing Casting (Explicit) in Java?
- Type casting in JavaScript.
- Type Casting operators in C++
- Java Type Casting Examples
- const_cast in C++ - Type casting operators
- What is Type casting in C#?
- Difference Between Type casting and Type Conversion
- What are explicit type conversions in C#?
- What is the difference between type conversion and type casting in C#?
- PHP Casting Variable as Object type in foreach Loop
- HTML5 data-* attribute type casting strings and numbers
- What are implicit and explicit type conversions in C language?
- What is the difference between implicit and explicit type conversion in C#?
- What are up-casting and down-casting in Java?

Advertisements