Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

NAME :- SUBHANKAR DAS

STUDENT CODE :- BWU/DCS/23/032


COURSE NAME :- COMPUTER PROGAMING
COURSE CODE :- ES202
PROGRAM NAME :- DIP CSE
SECTION :- A
TOPIC :- Typecasting
in arithmetic
expressions
TYPE CASTING
In C programming, type casting (also known as type
conversion) allows you to convert a variable from one data
type to another .

TYPE CASTING

Implicit Type Explicit Type


Casting Casting
Advantages of Type Casting
• Type casting in C programming makes the program very
lightweight.

Type representation and hierarchies are some features we


can take advantage of with
the help of typecasting.

Type casting helps programmers to convert one data type to


another data type.
o Implicit Type Casting :-
 Implicit type casting automatically converts the data type of a
variable without using the actual value that the variable holds.
 It performs conversions without altering the values stored in
the data variable.
 When converting from a lower data type to a higher data type,
the conversion occurs automatically.
 For example, if you divide an integer by a float, the result will
be implicitly converted to a float.

example :

#include <stdio.h>
int main()
{
int a = 15, b = 2;
float div;
div = a / b; // Implicit type casting
printf("The result is %f\n", div);
return 0;
}
Output – The result is 7.000000
o Explicit Type Casting :-
 Explicit type casting involves forcing the conversion
between data types.
 You explicitly define the type conversion within the
program.
 For example, when we need to change the data type of
a variable to get the correct output.

Example :
#include <stdio.h>
int main()
{
int a = 15, b = 2;
char x = 'a';
double div ;
div = (double)a / b; // Explicit type casting
x = x + 3;
printf("The result of Implicit typecasting is %c\n", x);
printf("The result of Explicit typecasting is %f", div);
return 0;
}
Output : The result of Implicit typecasting is ‘d’
The result of Explicit typecasting is 7.500000
THANK YOU

You might also like