Dab tsi yog pointer hauv C ++ nrog piv txwv yooj yim?
Dab tsi yog pointer hauv C ++ nrog piv txwv yooj yim?

Video: Dab tsi yog pointer hauv C ++ nrog piv txwv yooj yim?

Video: Dab tsi yog pointer hauv C ++ nrog piv txwv yooj yim?
Video: Python! Flattening Nested Lists 2024, Tej zaum
Anonim

Cov taw qhia hauv C++

Taw tes yog variable nyob rau hauv C++ uas tuav qhov chaw nyob ntawm lwm qhov sib txawv. Lawv muaj cov ntaub ntawv hom ib yam li cov hloov pauv, rau piv txwv ib hom integer taw tes tuaj yeem tuav qhov chaw nyob ntawm tus lej sib txawv thiab hom cim taw tes tuaj yeem tuav qhov chaw nyob ntawm char variable

Ntxiv rau qhov no, tus pointer C ++ yog dab tsi?

A taw tes yog qhov sib txawv uas tuav lub cim xeeb chaw nyob qhov twg tus nqi nyob. A taw tes tau tshaj tawm siv tus neeg teb xov tooj * ua ntej tus cim. Raws li C++ yog hom lus statically ntaus ntawv, hom yuav tsum tau tshaj tawm a taw tes . Peb tau pib a taw tes , tab sis nws taw tes nowhere, nws tsis muaj chaw nyob nco.

Ib yam li ntawd, vim li cas koj thiaj siv pointers hauv C ++? Ib vim li cas siv pointers yog thiaj li hloov tau los yog ib yam khoom ua tau hloov kho nyob rau hauv ib tug hu ua function. Hauv C++ nws yog kev xyaum zoo dua siv siv dua taw tes . Qhov no ua rau nws yooj yim rau hloov txoj kev hu xov tooj muaj nuj nqi tsis muaj rau hloov cov semantics ntawm dhau nws.

Ntxiv rau qhov no, Pointer muab piv txwv li cas?

A taw tes yog qhov sib txawv uas khaws qhov chaw nyob ntawm lwm qhov sib txawv. Tsis zoo li lwm yam kev hloov pauv uas tuav cov txiaj ntsig ntawm qee yam, taw tes tuav qhov chaw nyob ntawm qhov sib txawv. Rau piv txwv , ib qho kev sib txawv integer tuav (lossis koj tuaj yeem hais khw muag khoom) tus nqi integer, txawm li cas los xij tus lej taw tes tuav qhov chaw nyob ntawm tus lej sib txawv.

Yuav ua li cas koj tsim tus pointer variable hauv C ++?

Tsim tus taw tes hloov pauv nrog lub npe ptr, uas taw tes rau ib txoj hlua sib txawv , los ntawm kev siv lub hnub qub kos npe * (hlua * ptr). Nco ntsoov tias hom ntawm cov taw tes yuav tsum phim lub hom sib txawv koj ua haujlwm nrog.