Computer Science, asked by lakshmisha36, 4 months ago

explain two types of type converstion along with an example? in c program​

Answers

Answered by manyamurgai
1

Answer:

In computer science, type conversion or typecasting refers to changing an entity of one datatype into another. There are two types of conversion: implicit and explicit. ... Explicit type conversion can also be achieved with separately defined conversion routines such as an overloaded object constructor

Answered by peachiYadav
0

Answer:

Type Conversion in C

A type cast is basically a conversion from one type to another. There are two types of type conversion:

Implicit Type Conversion

Also known as ‘automatic type conversion’.

Done by the compiler on its own, without any external trigger from the user.

Generally takes place when in an expression more than one data type is present. In such condition type conversion (type promotion) takes place to avoid loss of data.

All the data types of the variables are upgraded to the data type of the variable with largest data type.

bool -> char -> short int -> int ->

unsigned int -> long -> unsigned ->

long long -> float -> double -> long double

It is possible for implicit conversions to lose information, signs can be lost (when signed is implicitly converted to unsigned), and overflow can occur (when long long is implicitly converted to float).

Example of Type Implicit Conversion:

// An example of implicit conversion

#include<stdio.h>

int main()

{

int x = 10; // integer x

char y = 'a'; // character c

// y implicitly converted to int. ASCII

// value of 'a' is 97

x = x + y;

// x is implicitly converted to float

float z = x + 1.0;

printf("x = %d, z = %f", x, z);

return 0;

}

Output:

x = 107, z = 108.000000

Explicit Type Conversion–

This process is also called type casting and it is user defined. Here the user can type cast the result to make it of a particular data type.

Similar questions