Write a program to demonstrate implicit type conversion.
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
int j=2.54;
int k=’A’;
char c=87.5;
cout <<“ j= “<<j;
cout<<endl<<“ k= “<<k;
cout<<endl<<“ c= “<<c;
}
OUTPUT:
j= 2
k= 65
c= W
Explanation
The above program works as described in Table 9.5.
Example 9.10
Table 9.5 Examples of Implicit Type Conversion
ExpressionOutput
int j=2.54
A float value is assigned to integer variable. Here, 2 is assigned to j and fractional part will get
vanished.
int k=’A’;
A char type value is assigned to integer variable. Here, ASCII value of ‘A’ (65) is assigned ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.