Size_t C yog dab tsi?
Size_t C yog dab tsi?

Video: Size_t C yog dab tsi?

Video: Size_t C yog dab tsi?
Video: What is size_t in C? 2024, Kaum ib hlis
Anonim

Los ntawm Wikipedia: Raws li 1999 ISO C Txheem (C99), loj_t yog hom integer uas tsis tau kos npe tsawg kawg yog 16 me ntsis (saib ntu 7.17 thiab 7.18. Hom no yog siv los qhia txog qhov loj ntawm ib qho khoom. Lub tsev qiv ntawv ua haujlwm uas coj qhov ntau thiab tsawg los xav kom lawv yog hom lossis muaj hom rov qab los ntawm loj_t.

Kuj paub yog, qhov loj npaum li cas ntawm Size_t?

loj_t hom yog lub hauv paus unsigned integer hom C / C ++ lus. Nws yog hom ntawm qhov tshwm sim rov qab los ntawm sizeofoperator. Hom kev qhov loj yog xaiv kom nws khaws tau qhov siab tshaj plaws qhov loj ntawm ib qho theoretically ua tau array ntawm txhua yam. Ntawm 32-ntsis system loj_t yuav siv 32 ntsis, ntawm 64-ntsis ib 64-ntsis.

Ib tug kuj nug, Size_type lossis Size_t cov ntaub ntawv hom yog dab tsi? loj_t yog txhais raws li tus hom siv rau qhov loj ntawm ib yam khoom thiab yog platform dependent.container:: loj_type yog cov hom uas yog siv rau ces tus naj npawb ntawm cov khoom nyob rau hauv lub thawv thiab yog containerdependent.

Tom qab ntawd, lo lus nug yog, vim li cas Size_t siv?

Nws yog ib hom uas yog siv los sawv cev qhov loj ntawm cov khoom hauv bytes andis yog li ntawd siv raws li hom rov qab los ntawm qhov loj ntawm tus neeg teb xov tooj. loj_t los yog tej yam uas tsis tau kos npe yuav pom siv asloop variable li voj variables feem ntau ntau dua los yog sib npaug 0.

Puas yog Size_t thiab int?

loj_t yog siv los khaws qhov ntau thiab tsawg ntawm cov ntaub ntawv cov khoom, thiab tau lees tias muaj peev xwm tuav qhov loj ntawm cov ntaub ntawv uas qhov kev siv C tshwj xeeb tuaj yeem tsim. Cov ntaub ntawv no tej zaum yuav me me (nyob rau hauv tus naj npawb ntawm cov khoom), loj dua los yog raws nraim tib yam asunsigned int . loj_t hom yog lub hauv paus unsigned integertype ntawm C / C ++ lus.

Pom zoo: