What is Typecasting? Explain with examples.

What is Typecasting? Explain with examples.

Typecasting :
- C++ is very strict about type compatibility. Different variable types must be cast when their values are assigned to each other. Type cast operator is used for explicit type conversion of variables. A type name behaves as if it is a function for converting values to a designated type.
- Example :
average = sum/float(i);
- The variable ‘i’ is converted to float and used to calculate the average.

Explain typecasting.

- Typecasting enables data type conversion. C++ supports Implicit conversions and Explicit conversion. Implicit conversions automatically performed when a value is copied to a compatible type. If there is an operation between an int and a float, the int is promoted to float before performing operation.
- You can cast types explicitly as follows :
int i, j, k;
k = i * long(j);
Explain (scope resolution operator) :: operator with an example - C++
Explain :: operator with an example - :: Operator: ‘::’ is known as Scope Resolution Operator...
What is const qualifier? - C++
What is const qualifier? - The qualifier const can be applied to the declaration of any variable to indicate that its value will not be changed.....
Describe Selection – if and switch using C++
Describe Selection – if and switch using C++ - if is decision making control and its general for is:...
Post your comment