Jayashree Type Conversion
Jayashree Type Conversion
INTRODUCTION
Both Type conversions in C++ are used to convert one predefined type to anther type.
Type Conversion is the process of converting one predefined type into another typecasting is
the converting one predefined type into another type forcefully.
Explicit Type conversion is also called type casting. It is the conversion of one
operand to a specific type. An explicit conversion is a user defined that forces an expression
to be of specific type.
1
Syntax : (type) expression
Assigning a value of smaller data type to a larger data type, may not pose any
problem. But, assigning a value of larger data type to smaller type, may poses problems. The
problem is that assigning to a smaller data type may loose information, or result in losing
some precision.
6 long int ant the (i) long int (provided long int can Step 7
other is unsigned represent all values of unsigned int)
int
(ii) unsigned long int(if all values of Step 7
unsigned int cant be represented by long
int)
2
The step 1 and 2 in the above table will be read as
Step 1: If either operand is of type long double, the other is converted to long double.
Step2 : Otherwise, if either is of type double, the other is converted to double.
After applying above arithmetic conversions, each pair f operands is of same type and
the result of each operation is the same as the type of both operands.
CONVERSION PROBLEMS
3
AIM
ALGORTIHM
#include <stdio.h>
int main ()
int x;
x = (int) 7/5;
cout<<"x="<<x;
OUTPUT
CONCLUSION
4
Automatic Conversion otherwise called as Implicit Conversion
Explicit type conversions (casts) are used when a programmer want to get around the
compiler's typing system; for success in this endeavour, the programmer must use them
correctly. Problems which the compiler avoids may arise, such as if the processor demands
that data of a given type be located at certain addresses or if data is truncated because a data
type does not have the same size as the original type on a given platform. Explicit type
conversions between objects of different types lead, at best, to code that is difficult to read.
REFERENCES
https://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap13.html
http://www.geeksforgeeks.org/g-fact-35/
http://www.edugrabs.com/type-conversion-and-type-casting-in-c/
http://www-h.eng.cam.ac.uk/help/tpl/languages/C++/strongtyping.html
http://www.pvtuts.com/cpp/cpp-type-conversions