Type
Conversion & Type Casting ds ckjs esa ;fn fiNyk Programming
Experience gks
rks ge ;g tkurs gSa fd buds }kjk fdlh ,d Vkbi dh Value dks
nwljs Vkbi dh Value ds Variable esa Assign fd;k tkrk gSaA ;fn os
nksuks Types Compatible gSa rks Comparison rFkk Conversion
Automatically gks
tkrk gSaA fdlh ,d Vkbi dh Value dks lnSo mls cM+s Vkbi dh Value esa gh Assign fd;k tk ldrk gSa] ijUrq double dks byte esa Convert djuk gSa] rks mls Implicitly Convert ugha fd;k tk ldrk gSaA blds fy, Type Casting dh
vko’;drk gksrh gSa] ftlesa InCompatible
Type esa Conversion fd;k tk ldrk gSaA vr% Type Casting ds }kjk InCompatible
Types esa Explicit Conversion fd;s tkrs gSaA
Automatic
Type Conversion: -
blds vUrZxr tc ,d Vkbi ds MkVk dks nwljs Vkbi ds Variable esa Automatic
Convert dj
fn;k tkrk gSa rks bl izdkj ds Conversion dks Automatic Type dgrs gSaA ;g Conversion
rHkh gks ldrs
gSa tc fuEu nks ckrsa Satisfy gksrh gksa :-
(1) nksuks Types Compatible gksus pkfg;sA
(2) Source Type ftldk dh Conversion
fd;k tk jgk
gSa] Destination Type ls NksVh gksuh pkfg,A
tc ;s nksuks dkj.k Satisfy gksrs
gSa] rhkh Automatic Type ds Conversions fd;s tk ldrs gSaA
Example:
- byte, short, int, long
Character
of Boolean Type ds
Data dks Interchange
ugha fd;k tk
ldrkA
InCompatible Types Casting
TSklk fd
ge tkurs gSa fd Automatic
Type Conversion vklkuh ls Perform fd;s tk ldrs gSa] rFkk os User ds fy, Helpful Hkh gSa]
D;ksafd bl izdkj ds Conversion
esa
fdlh izdkj dh Extra
Types dh
vko’drk ugha gksrh gSa] ijUrq ;fn fdlh Integer Value dks Byte Value esa Convert djuk gSa]
rks og Automatic
Conversion ds }kjk ugha fd;k tk ldrk gSaA D;ksafd byte, integer ls NksVk
gSaA vr% bl izdkj ds Conversion
Explicitly fd;s tkrs gSaA vr% ;g dg ldrs gSa] fd In Compatible Type ds e/; Explicitly Conversion fd;s tkrs
gSa] ftUgsa Casting of
In Compatible Types dgk tkrk gSaA vr% blds fy, Syntax fuEu gSa%&
(Target Type) Value
Byte a;
int i;
a = (byte)i;
No comments:
Post a Comment