C++ : Type Conversion in hindi , Type conversion by assignment operator , Conversion in Expression c++ language

Type conversion by assignment operator , Conversion in Expression c++ language , C++ : Type Conversion in hindi :-
यूजर द्वारा किसी variable के type को पहले ही declare कर दिया जाता है | लेकिन प्रोग्राम को compile किया जाता है तब require data type, define data type से अलग होता है | उस condition मे , क्या किया जाता है |
अतः c++ मे type conversion की सुविधा दी गयी है |
c++ मे 11 type के integer type और 3 type के float type के data हो सकते है | कंप्यूटर के pass अलग अलग condition होती है जिसमे variable को handel किया जाता है |
इसके अलावा C++ मे निन्म type conversion आटोमेटिक होता है :-
1.C++ मे values आटोमेटिक convert हो जाती है जब किसी value को एक arithmatic type से दुसरे airthmatic type मे assign किया जाता है |
2.C++ value को convert कर देता है जब किसी expression मे दो या दो से अधिक data type को मिक्स किया जाता है |
3.C++ मे value को convert की जाती है जब इन्ही function मे pass किया जाता है |
अगर आप आटोमेटिक type कन्वर्शन को नहीं समज सके तो निन्म discussion को जरुर पढ़े |
 
Type conversion by assignment operator
C++ मे किसी type के data value को दुसरे data type के variable मे assign किया जा सकता है | इस प्रकार value का type उस variable के data type मे convert हो जाता है जिसमे इसे assign किया गया है | उदाहरण के लिए :
#include<iostram.h>
#include<conio.h>
void main()
{
using namesapce std;
float a= 67;
int b=3.223;
int c=3.445e8;
cout<<“value of a : “<<a<<endl;
cout<<“value of b : “<<b<<endl;
cout<<“value of c : “<<c<<endl;
getch();
}
उपर दिए गये उदहारण मे ,
statement float a= 67 ; से integer value 67 को float मे convert किया जाता है |
statement int b=3.223; से float value 3.223; को integer मे convert किया जाता है |
statement int c=3.445e8 ; से float value 3.445e8 को integer मे convert कर दिया जाता है |
किसी upper range वाले variable मे conversion करना मुश्किल नहीं होता है जैसे integer से long integer  या double से long double मे | और किसी कम range से बड़े range मे conversion करने से variable की value पर कोई effect नहीं पड़ता है |लेकिन value द्वारा assign की जनि वाली bits की सख्या बढ़ जाती है |
नीचे दी गयी table मे type conversion की लिस्ट है :
bigger floating point type to smaller floating point type :- double to
float
Result will be undefined. Output must
be out of range for target type.
Floating point type to integer
type
In this case , fractional value
will be eliminated
Bigger integer type to smaller
integer type
Result will be undefined. Output must
be out of range for target type.
floating number को integer type मे convert करने के लिए प्रॉब्लम होती है |इसके लिए floating point को turcating किया जाता है |जिससे fraction value को convert किया जाता है |
Conversion in Expression
जब दो या दो से अधिक type के operands को expression मे add किया जाता है | तो expression मे आटोमेटिक conversion होता है |
या तो कोई type आटोमेटिक convert हो जाता है | या जब कोई variable किसी दुसरे variable से connect होता है तब convert होता है |
उदाहरण के लिए जब कोई bool , char , unsigned char , signed char ,integer के साथ include होता है तब ये भी integer type मे convert हो जाता है | उदाहरण के लिए
#include<iostram.h>
#include<conio.h>
void main()
{
using namesapce std;
int a= 67;
char b=a;
int c= a+b;
cout<<“value of a : “<<a<<endl;
cout<<“value of b : “<<b<<endl;
cout<<“value of c : “<<c<<endl;
getch();
}इस उदाहरन मे , statement int c= a+b; मे character type data integer मे convert हो जाता है इसे a के साथ add किया जाता है|

इस type के conversion की limit होती है :
1.unsigned short type ,integer मे convert हो जाता है अगर short type इन्त्गेर से छोटी है |
2.अगर short और integer दोनों same size की होगी तब unsigned short ,unsigned integer मे convert हो जाता है |
3.जब integer त्योए को float के साथ use किया जाता है तब छोटी value  ,बड़ी value मे convert हो जाती है |
4.अगर दोनों operand मे से एक long double type हो तब non long double type , long double मे convert हो जाता है |
5.अगर दोनों operand मे से एक  double type हो तब non  double type ,  double मे convert हो जाता है |
6.अगर दोनों operand मे से एक float type हो तब non float type , float मे convert हो जाता है |
7.अगर दोनों operand मे से एक integer type  हो तब inter changable हो सकता है |
8.अगर दोनों integer मे से एक unsigned integer है तब signed integer , unsigned integer मे convert हो जाता है |
9.अगर एक unsigned और दूसरा long type है तब conversion दोनों variable की size पर निर्भर करता है |
10.अगर दोनों integer मे से एक long integer है तब  integer , long integer मे convert हो जाता है |

C++ उपर दिए सभी type conversion के rules को फॉलो करता है लेकिन K&R  C language मे कुछ और rule होता है |

उदाहरण होगा :

#include<iostram.h>
#include<conio.h>
void main()
{
using namesapce std;
int a= 67;
long int b= 677;
int c= a+b;
cout<<“value of a : “<<a<<endl;
cout<<“value of b : “<<b<<endl;
cout<<“value of c : “<<c<<endl;
getch();
}

Type Cast
C++ मे manually type conversion possible है इसका syntax होता है :
type(variable name );
यहा पर
type : ये convert करने के दिए गये data type को define करता है |
variable name : ये variable का नाम है जिसे convert करना है |
C language मे type conversion का syntax थोडा change होता है इसका syntax होता है :
(type)variable name ;

उदाहरण के लिए :

#include<iostram.h>
#include<conio.h>
void main()
{
using namesapce std;
int a,b;
float c;
cout<<“Enter value 1″<<endl;
cin>>a;
cout<<“Enter Value 2″<<endl;
cin>>b;
c=a/b;
cout<<“Value of output”<< int(c) << endl;
int d= a+b;
cout<<“Value of Addition :”<< d << endl;
getch();
}इस उदाहरण मे , int(c) type conversion statment है जिससे ‘c’ जो की float type होती है इससे integer type मे convert कर देते है |

इस article मे type conversion के आटोमेटिक और manually conversion को discuss किया है आगे वाले article मे compound data type को discuss करेगे |