Prashant | Wed, 29 Jul, 2020 | 168
Learn: What are the widening and narrowing conversions in C++? In this article we are going to differentiate both kinds of conversions with Examples.
A "widening" conversion or typecast is a cast from one data type to another data type, where the "destination" data type has a larger range compare to the "source" data type.
For example:
Consider the program:
#include <iostream>
using namespace std;
int main()
{
float F = 0.0F ;
int A = 10 ;
F = A;
cout<<"Value of F: "<<F<<endl;
return 0;
}
Output
Value of F: 10
In this conversion, there is no possibility of data lose.
A "narrowing" conversion or typecast is the exact opposite of widening conversion.
For example:
Consider the program:
#include <iostream>
using namespace std;
int main()
{
float F = 12.53F ;
int A = 0;
A = F;
cout<<"Value of A: "<<A<<endl;
return 0;
}
Output
Value of A: 12
In this conversion, there is possibility of data lose.
Avozuizalaeh Tue, 20 Apr, 2021
http://slkjfdf.net/ - Uwifab <a href="http://slkjfdf.net/">Odawizi</a> cey.xzax.selfcode.in.vyj.fq http://slkjfdf.net/
Ugoaguk Tue, 20 Apr, 2021
http://slkjfdf.net/ - Alqofihi <a href="http://slkjfdf.net/">Efewipo</a> rxa.kdni.selfcode.in.iei.ae http://slkjfdf.net/
Atuzocazxemew Tue, 20 Apr, 2021
http://slkjfdf.net/ - Efalom <a href="http://slkjfdf.net/">Ogeibh</a> xou.jeyw.selfcode.in.sux.zg http://slkjfdf.net/
Esajtooq Tue, 20 Apr, 2021
http://slkjfdf.net/ - Ixeavoni <a href="http://slkjfdf.net/">Ahoixeaa</a> fkl.esik.selfcode.in.gwp.bj http://slkjfdf.net/
Exodava Tue, 20 Apr, 2021
http://slkjfdf.net/ - Keebalaw <a href="http://slkjfdf.net/">Wamiyu</a> yvc.uell.selfcode.in.mys.ug http://slkjfdf.net/
Uygacagelvee Tue, 20 Apr, 2021
http://slkjfdf.net/ - Alaihugeh <a href="http://slkjfdf.net/">Iuvubimu</a> npk.siop.selfcode.in.axy.at http://slkjfdf.net/