Tus neeg teb xov tooj postfix yog dab tsi hauv C ++?
Tus neeg teb xov tooj postfix yog dab tsi hauv C ++?

Video: Tus neeg teb xov tooj postfix yog dab tsi hauv C ++?

Video: Tus neeg teb xov tooj postfix yog dab tsi hauv C ++?
Video: Pheej Lauj/Pom Tus Neeg Txawv Tej Duab nkauj tawm tshiab/Official MV/Original Music 2024, Cuaj hlis
Anonim

Postfix operators yog unary operators uas ua haujlwm ntawm ib qho kev sib txawv uas tuaj yeem siv los nce lossis txo tus nqi los ntawm 1 (tshwj tsis yog overloaded). Muaj 2 postfix operators hauv C ++, ++ thiab --.

Tib neeg kuj nug, qhov txawv ntawm ++i thiab kuv ++ hauv C yog dab tsi?

Lub xwb txawv yog qhov kev txiav txim ntawm kev ua haujlwm nruab nrab tus nce ntawm qhov sib txawv thiab tus nqi tus tus neeg ua haujlwm rov qab los. Yog li pib ++ kuv rov qab tus nqi tom qab nws yog incremented, thaum ++ kuv rov qab tus nqi ua ntej nws yog incremented. Thaum kawg, nyob rau hauv ob qho tib si kuv yuav muaj nws tus nqi incremented.

Tom qab ntawd, lo lus nug yog, qhov txawv ntawm prefix thiab postfix ntawm -- thiab ++ tus neeg teb xov tooj yog dab tsi? Nyob rau hauv lub prefix version (piv txwv li, ++ i), tus nqi ntawm kuv yog incremented, thiab tus nqi ntawm kev qhia yog tus nqi tshiab ntawm i. Hauv postfix version (i.e., i++), tus nqi ntawm kuv yog incremented, txawm li cas los xij, tus {tus nqi | tus nqi} ntawm qhov kev qhia yog tias tus nqi qub ntawm i.

Ib tug kuj yuav nug, dab tsi yog postfix thiab prefix hauv C ++?

Qhov sib txawv ntawm ob yog tias nyob rau hauv postfix cim, tus neeg teb xov tooj tshwm tom qab postfix -expression, whereas nyob rau hauv lub ua ntej sau, tus neeg teb xov tooj tshwm ua ntej qhia, piv txwv li x--; npe postfix -decrement tus neeg teb xov tooj thiab-x; npe ua ntej decrement operator.

++ kuv thiab kuv ++ hauv Java yog dab tsi?

Ntawm no ++ hais txog nce los ntawm 1. Tam sim no ++ kuv hais txog cov nce ntawm tus nqi khaws cia hauv qhov sib txawv i. Qhov twg yog kuv ++ hu ua post nce tus neeg teb xov tooj, ntawm no thaum lub compiler executes cov nqe lus no ces thawj tus nqi yog hloov nyob rau hauv qhov sib npaug thiab ces tus nqi yog incremented los ntawm 1.