Welcome to YLOAN.COM
yloan.com » misc » Types Of Conversions In An Expressions
Gadgets and Gizmos misc Design Bankruptcy Licenses performance choices memorabilia bargain carriage tour medical insurance data

Types Of Conversions In An Expressions

Conversions are defined like operators and are named for the type to which they convert

. There are basically two types of conversion:

1. Implicit Type Conversion

2. Explicitly Type Conversion.

Implicit type conversion


C permits mixing of constants and variables of different types in an expression. C automatically converts any intermediate values to the proper type so that the expression can be evaluated without losing any significance. This automatic type conversion is know as implicit type conversion

During evaluation it adheres to very strict rules and type conversion. If the operands are of different types the lower type is automatically converted to the higher type before the operation proceeds. The result is of higher type.

The following rules apply during evaluating expressions

All short and char are automatically converted to int then

1).If one operand is long double, the other will be converted to long double and result.will be long double.

2). If one operand is double, the other will be converted to double and result will be double.

3). If one operand is float, the other will be converted to float and result will be float.

.

4). If one of the operand is unsigned long int, the other will be converted into unsigned long int and result will be unsigned long int.

.

5). If one operand is long int and other is unsigned int then

a. If unsigned int can be converted to long int, then unsigned int operand will be converted as such and the result will be long int.

.b. Else Both operands will be converted to unsigned long int and the result will be .unsigned long int.

.

6). If one of the operand is long int, the other will be converted to long int and the result will be long int. .

7). One operand is unsigned int the other will be converted to unsigned int and the .result will be unsigned int.

Explicit Conversion

Many times there may arise a situation where we want to force a type conversion in a way that is different from automatic conversion.

Consider for example the calculation of number of female and male students in a class

Ratio = female_students / male_students


Since if female_students and male_students are declared as integers, the decimal part will be rounded off and its ratio will represent a wrong figure. This problem can be solved by converting locally one of the variables to the floating point as shown below.

Ratio = (float) female_students / male_students

The operator float converts the female_students to floating point for the purpose of evaluation of the expression. Then using the rule of automatic conversion, the division is performed by floating point mode, thus retaining the fractional part of the result. The process of such a local conversion is known as explicit conversion or casting a value. The general form is (type_name) expression .

by: pankaj11
Serious Injury - Finding Lawyers For Serious Settlements Should You Buy Backlinks Or Not? Toddler Nap Mats Do You Want To Enjoy The Adrenaline Rush? Finding A Reputable Loose Diamonds Store Simpler Shifting By Professionals Of Bangalore What Are The Basic Questions Which You Need To Answer Before Deciding Upon A Pos System For Your Foo Used Hyundai - Buyers Guide A Look Into The Aspects Of A Hcg Diet Hosted Predictive Dialer: A Perfect Contact Center Solution Back Pain As A Symptom Of Hemophilia Lose 20 Pounds In One Week? Possible? Lose 10 Pounds In 2 Weeks With These Simple Steps!
print
www.yloan.com guest:  register | login | search IP(216.73.216.250) California / Anaheim Processed in 0.017421 second(s), 7 queries , Gzip enabled , discuz 5.5 through PHP 8.3.9 , debug code: 54 , 3089, 85,
Types Of Conversions In An Expressions Anaheim