04
Nov
Implicit Type Conversions
Related Blog Items
- Implicit Type Conversions - part 2
- C++ Advanced Tutorial - Lesson 10
- Why sizeof is an operator, not a function?
- Cross Casts
- How is "const correctness" related to ordinary type safety?
An expression e of a given type is implicitly converted if used in one of the following situations:
- Expression e is used as an operand of an arithmetic or logical operation.
- Expression e is used as a condition in an if statement or an iteration statement (such as a for loop). Expression e will be converted to bool (or int in C).
- Expression e is used in a switch statement. Expression e will be converted to an integral type.
- Expression e is used in an initialization. This includes the following:
- An assignment is made to an lvalue that has a different type than e.
- A function is provided an argument value of e that has a different type than the parameter.
- Expression e is specified in the return statement of a function, and e has a different type from the defined return type for the function.
The compiler will allow an implicit conversion of an expression e to a type T if and only if the compiler would allow the following statement:
T var = e;
For example when you add values having different data types, both values are first converted to the same type: when a short int value and an int value are added together, the short int value is converted to the int type.
You can perform explicit type conversions using one of the cast operators, the function style cast, or the C-style cast.
[tags] type casting [/tags]
Popularity: 4%
You need to log on to convert this article into PDF
Related Blog Items - Implicit Type Conversions - part 2
- C++ Advanced Tutorial - Lesson 10
- Why sizeof is an operator, not a function?
- Cross Casts
- How is "const correctness" related to ordinary type safety?
Related Blog Items
- Implicit Type Conversions - part 2
- C++ Advanced Tutorial - Lesson 10
- Why sizeof is an operator, not a function?
- Cross Casts
- How is "const correctness" related to ordinary type safety?
No Comments
No comments yet.