Yuav ua li cas koj instantiate ib array?
Yuav ua li cas koj instantiate ib array?

Video: Yuav ua li cas koj instantiate ib array?

Video: Yuav ua li cas koj instantiate ib array?
Video: Thov Txim Qhov Kuv Txav Deb Ntawm Koj (Official Music Video 2022) N. Vajxob Xyooj & N. Vanxay lauj 2024, Kaum ib hlis
Anonim

Rau instantiate ib array , siv no syntax: arrayName = tshiab datatype[size]; qhov luaj li cas yog ib qho kev qhia uas ntsuas rau tus lej thiab qhia cov naj npawb ntawm cov ntsiab lus. Thaum ib array yog instantiated , cov ntsiab lus raug muab qhov tseem ceeb raws li qhov array hom ntaub ntawv.

Raws li kev sib raug zoo, koj ua li cas instantiate ib qho array hauv Java?

Instantiating Array hauv Java var-name = hom tshiab [size]; Ntawm no, hom qhia hom ntaub ntawv raug faib, qhov loj qhia cov naj npawb ntawm cov ntsiab lus hauv array , thiab var-name yog lub npe ntawm array variable uas yog txuas rau lub array.

Kuj Paub, ua li cas koj instantiate ib qho array hauv C ++? Pib qhov Array hauv C++ Koj tuaj yeem ua tau pib qhov array thaum koj tshaj tawm nws los ntawm kev suav nrog thawj qhov tseem ceeb hauv braces tom qab tshaj tawm. Rau me me array , qhov no yooj yim: int nCount[5] = {0, 1, 2, 3, 4}; Ntawm no tus nqi ntawm nCount[0] yog pib rau 0, nCount[1] rau 1, nCount[2] rau 2, thiab lwm yam.

Kuj paub yog, koj ua li cas pib ib qho array?

Yog koj xav tau pib ib array , sim siv Array Initializer: int data = {10, 20, 30, 40, 50, 60, 71, 80, 90, 91}; // los yog int data; data = new int {10, 20, 30, 40, 50, 60, 71, 80, 90, 91}; Pom qhov txawv ntawm ob qhov kev tshaj tawm. Thaum muab tus tshiab array mus rau ib qho kev hloov pauv tau tshaj tawm, yuav tsum tau siv tshiab.

Dab tsi yog qhov tsim nyog array pib?

Qhov pib pib ua ntej los ntawm qhov sib npaug (=). Koj tsis tas yuav pib tag nrho cov ntsiab lus hauv ib array . Yog ib array yog ib nrab pib , cov ntsiab lus uas tsis yog pib txais tus nqi 0 ntawm cov tsim nyog hom. Tib yam siv rau cov ntsiab lus ntawm arrays nrog lub sijhawm khaws cia zoo li qub.

Pom zoo: