Explain type casting, C/C++ Programming

Assignment Help:

Type Casting

Implicit type conversions, as allowed by the language, can lead to errors creeping in the program if care is not taken. Thus, explicit type conversions may be used in mixed mode expressions. This is done by type-casting a value of a certain type, into the desired type. This is done by using the (type) operator as follows:

                (type) expression

expression is changed to the given type by the rules stated above.

e.g.

float a = 10.0, b = 3.0, c;

c = a / b;

This expression will result in 3.333333 being stored in 'c'. If the application needs integer division of two floating point numbers, then the following expression with the type cast can be used:

                c = (int)a / (int)b;

                                or

                c = (int) (a / b);

 


Related Discussions:- Explain type casting

Should my class declare a friend function or member function, A: Use a memb...

A: Use a member while you can and a friend when you need to. Sometimes friends are better syntactically (e.g., in class Fred, friend functions let the Fred parameter to be secon

Can any constructor throw an exception?, Can any constructor throw an excep...

Can any constructor throw an exception? How to handle error while the constructor fails?

Smuggler, Smugglers are becoming very smart day by day. Now they have devel...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Computer Science 101, This is what I need help with. "Create a program cre...

This is what I need help with. "Create a program creates an interface allowing the user to select from some other programs I have made one being a money converter and the other ca

Boardcoloring., Smugglers are becoming very smart day by day. Now they have...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

What is inheritance, What is inheritance? Class, the vehicle, which is ...

What is inheritance? Class, the vehicle, which is used to execute object-oriented concepts in C++, has given a new dimension to this idea of reusability. Many vendors now offer

Stack push pop, 2 flowcharts, pseudocode for each (at least 4 algorithms), ...

2 flowcharts, pseudocode for each (at least 4 algorithms), and code for either a stack or a queuestion..

String-classes-constructors and member functions, Objective Using C++ s...

Objective Using C++ string, classes, constructors and member functions. Task A Write a program (book.cpp) to store a list of book titles and the published dates. Your pro

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd