Subject: C' Programming For Problem Solving Subject Code: 18CPS23
Subject: C' Programming For Problem Solving Subject Code: 18CPS23
x = l / i + i * f - d
float
float double
double
int double
Implicit Type Conversion (CONTD….)
Example Program 1: Because here „b‟ is
#include<stdio.h> character type, „a‟ is
integer type so C language
void main()
provides implicit type
{
conversion of „b‟ (char
char b = „A‟; type) into integer
int a; type.
a = b;
ASCII value of A is 65, so it
printf(“%d”,a);
displays 65
}
Output : 65
Implicit Type Conversion (CONTD….)
Example Program 2:
#include<stdio.h>
void main()
{
double d = 123.456;
int a;
a = d;
printf(“%d”,a);
}
Output : 123
Explicit Type Conversion
of specific type.
as Type Casting.
(dat_type) expression
Explicit Type Conversion (CONTD….)
Example Program :
#include<stdio.h> This #include<stdio.h>
program
void main() can be void main()
changed as
{ {
int a = 4; Here „a‟ is int a = 4;
float b; explicitly float b;
changed from
b = 1/a; b = 1/(float)a;
int data
printf(“%d”,b); printf(“%d”,b);
type to
} float data }
type
Output : 0.000000 Output : 0.250000
Explicit Type Conversion (CONTD….)
Example Action
Example:
x = (int)(y+0.5); if y = 27.6
The value of x = 28