Yuav ua li cas arrays sawv cev hauv kev nco?
Yuav ua li cas arrays sawv cev hauv kev nco?

Video: Yuav ua li cas arrays sawv cev hauv kev nco?

Video: Yuav ua li cas arrays sawv cev hauv kev nco?
Video: Yuav ua li cas thiaj khiav dim lub ntiajteb no 2024, Hlis ntuj nqeg
Anonim

Arrays feem ntau sawv cev nrog daim duab ntawd sawv cev lawv nco siv. Pointers tuav lub nco chaw nyob ntawm lwm cov ntaub ntawv thiab yog sawv cev los ntawm ib tug dub disk nrog ib tug xub taw tes rau cov ntaub ntawv nws references. Qhov tseeb array variable, ib qho piv txwv no, yog tus taw tes rau qhov nco rau tag nrho nws cov ntsiab lus.

Ib yam li ntawd, tib neeg nug, arrays khaws cia hauv lub cim xeeb li cas?

Ib array khaws nws cov khoom sib txuas nco qhov chaw. Yog koj tsim lub array hauv zos nws yuav nyob rau pawg. Qhov twg cov ntsiab lus yog khaws cia nyob ntawm qhov chaw cia khoom specification. Ib tug dynamically tsim array yuav tsim nyob rau hauv heap.

Tom qab ntawd, lo lus nug yog, pes tsawg hom array tuaj yeem sawv cev hauv kev nco? Yog li tsib lub ntsiab yuav khaws cia hauv tsib qhov chaw nyob ib sab hauv nco . koj ua tau saib qhov no los ntawm referencing lub nco chaw nyob ntawm txhua lub ntsiab lus. Tsis zoo li lwm cov ntaub ntawv qub hom in C, ib array ID (ntawm no, arr) nws tus kheej sawv cev nws pointer.

Ib yam li ntawd, nws yog nug, dab tsi yog array hauv nco?

Ib array yog ib tug sau ntawm homogeneous (tib hom) cov ntaub ntawv cov khoom khaws cia nyob rau hauv contiguous nco qhov chaw. Piv txwv li yog ib array yog hom "int", nws tsuas tuaj yeem khaws cov lej suav thiab tsis tuaj yeem tso cai rau cov ntsiab lus ntawm lwm hom xws li ob npaug, ntab, char thiab lwm yam.

Yuav ua li cas yog ob seem arrays sawv cev nco?

  1. Sawv cev ntawm ob seem array nyob rau hauv lub cim xeeb yog kab loj thiab kab loj.
  2. Ib 2D array muaj ib hom xws li int lossis String, nrog ob khub ntawm square brackets.
  3. Ib tug ob-dimensional matrix a, ob qhov chaw nyob qhov chaw yuav tsum tau mapped rau ib-dimensional chaw nyob.

Pom zoo: