What is Type Conversion and Type Casting in C++ programming
Hello friends aaj hum C++ programming Language ke articals ko aage badate hui baat karege ki C programming me type Conversion jisko type Casting bhi kahte hai kya hote hai aur kaise inko program me use kiya jata hai to chaliye let me starts.
- What is Type Conversion and Type Casting
Computer me kai baar kai Parts me jarurat ke hisaab se kai tarah ke type Conversion hote rahte hai. Kuch Conversion complier khud hi kar leta hai. Aur kai baar hume apni jarurat ke hisab se kuch Conversion karne padte hai. For example- Maan lo hume kisi float prakar ki sankhya ko integer me convert karne pad sakta hai ya phir kisi integer type ko character me convert karna pad sakta hai to chaliye ek example ke through samghte hai.
int n = 20;
float PI = 3.1415;
n = PI + n;
// The Value is automatically converted to 20.0
cout << PI – 2;
// The value 2 is automatically converted to 2.0
Is code segment me jab integer prakar ke variable me Pl ke float ko jodna+ karna hota hai to compile automatically hi n ke maan ko 20 ko float ke maan ko 20.00 me convert kar deta hai. Aur float prakar ke maan hi return karta hai. Lekin assignment operator ke left me ek n ek integer prakar ka variable hai. Isliye n me return hone wale float prakar ke maan ka kewal integer part hi store karta hai aur point . Wale maan ko compile khud hi ignor kar deta hai. Aisa karne ke liye hum jis process ko use karte hai usse hi Type Casting ya Type Conversion karna kahte hai. Kyoki is process me ek Data Types dusre Data type me convert kiya jata hai.
Maan lo ki Conversion type CV wah type hai jise value V ko convert karke converted Type CT me store karna hai. To hume is Conversion ko perform karne ke liye is tarah se statement likh na padega.
CT=(CV)V
Maan lo V ek float prakar ka maan hai jise integer me convert karke ek integer prakar ke variable me store karna hai. To is Type Casting ko perform karne ke liye hume is prakar ki statements write karna padega.
Code Segment 02
int CT;
float V = 123.699;
CT = (int)V;
cout << CT; // Value of CT would be 123 After Type Casting
Aap is example me do baate dhek sakte hai 1st ye ki integer prakar ka maan float prakar ke maan me convert ho raha hai. Jab hum chote type ke Data type se badhe size ke data type me convert hota hai. To sab Conversion compile ke thorough automatically hota hai. Jaise ki pahle wale code segment me hua hai. Isliye is Type ki type Casting ko Automatica Type Casting kahte hai. Ab aap jan gaye hoge ki C++ Programming language me type Casting kya hai aur hum ise kaise use kar sakte hai. Yah Artical aapko acha laga ho to isse social media par share kare.
int CT;
float V = 123.699;
CT = (int)V;
cout << CT; // Value of CT would be 123 After Type Casting
Aap is example me do baate dhek sakte hai 1st ye ki integer prakar ka maan float prakar ke maan me convert ho raha hai. Jab hum chote type ke Data type se badhe size ke data type me convert hota hai. To sab Conversion compile ke thorough automatically hota hai. Jaise ki pahle wale code segment me hua hai. Isliye is Type ki type Casting ko Automatica Type Casting kahte hai. Ab aap jan gaye hoge ki C++ Programming language me type Casting kya hai aur hum ise kaise use kar sakte hai. Yah Artical aapko acha laga ho to isse social media par share kare.