Puas yog char an int?
Puas yog char an int?

Video: Puas yog char an int?

Video: Puas yog char an int?
Video: Chair Yoga for restricted mobility & Seniors 65 and up - 20 Minutes 2024, Kaum ib hlis
Anonim

Ib int yuav tsum yog tsawg kawg yog 16 cov lus kos npe, thiab lees txais tag nrho cov txiaj ntsig ntawm -32767 thiab 32767. Qhov ntawd txhais tau tias ib qho int tuaj yeem lees txais txhua qhov txiaj ntsig los ntawm a char , yog tus kos npe tom kawg lossis tsis tau kos npe. Yog tias koj xav khaws cov cim hauv qhov sib txawv, koj yuav tsum tshaj tawm nws li char.

Hais txog qhov no, qhov txawv ntawm char thiab int yog dab tsi?

' Int 'thiab' char ' yog ntau hom ntaub ntawv siv nyob rau hauv ntau hom computer programming lus. ' Int ' khw muag khoom tsuas yog qhov muaj nuj nqis, qhov twg ' char ' khaws cov cim thiab. Cov txawv yog qhov loj me hauv byte ntawm qhov sib txawv, thiab los ntawm qhov ntawd qhov txawv ntsuas qhov sib txawv tuaj yeem tuav.

Tsis tas li ntawd, vim li cas char yog ib hom ntaub ntawv suav? Yog li ntawd, a char ib txwm nyob raws nraim ib byte, uas yuav tsum yog tsawg kawg yog 8 khoom. Yog tias nws loj dua, nws tseem nyob raws nraim ib byte - tab sis qhov byte tshwm sim loj dua 8 ntsis. Kev tsis sib xws hom tuaj yeem khaws tag nrho tus lej muaj nuj nqis mus txog rau tus naj npawb ntawm cov khoom siv encoding siv los piav txog qhov tseem ceeb hom.

Tsis tas li ntawd, tus nqi ntawm char A yog dab tsi?

Kos npe thiab tsis kos npe

Hom Loj Ntau yam ntawm tus nqi
int 2o4 ib -32, 768 txog 32, 767 lossis -2, 147, 483, 648 txog 2, 147, 483, 647
unsigned ua 2o4 ib 0 mus rau 65, 535 los yog 0 rau 4, 294, 967, 295
char 1 byte ib -128 rau 127 lossis 0 txog 255
kos npe char 1 byte ib -128-127: kuv

Koj puas tuaj yeem ntxiv char rau ib qho int hauv C?

A char sawv cev a tus cwj pwm los ntawm coding nws mus rau hauv ib qho int . Yog li piv txwv li ' c ' yog coded nrog 49. Thaum koj ntxiv lawv ua ke, koj get ib int uas yog tus lej ntawm cov cai ntawm lub char thiab tus nqi ntawm cov int . '1' yog tus lej, tsis yog tus lej, thiab tau muab tso rau hauv ASCII kom muaj nuj nqis 49.

Pom zoo: