Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Predavanje niza funkciji
Author Message
MetalGenius Offline
Novi korisnik
*

Posts: 46
Joined: Oct 2011
Reputation: 3
Post: #1
Predavanje niza funkciji
Poz raja, moze li mi neko reci postoji li nacin da se kompletan niz preda funkciji, bio on staticki ili dinamicki alociran.
Hvala He he

I can't escape myself.
23-12-2011 10:34 AM
Find all posts by this user Quote this message in a reply
Gogy Offline
____
*

Posts: 2,379
Joined: Feb 2006
Post: #2
RE: Predavanje niza funkciji
Misliš na ovo?

Code:
function doSomething(int niz[]) {
   ...
}

int niz[] = {1,2,3,4,5};
doSomething(niz);

Pravila foruma | Twitter - Facebook - Google+ |
23-12-2011 12:33 PM
Visit this user's website Find all posts by this user Quote this message in a reply
danielvast Offline
Forumaš
***

Posts: 432
Joined: Dec 2009
Reputation: 22
Post: #3
RE: Predavanje niza funkciji
A može i ovako

Code:
function doSomething(int *niz) {
   ...
}

int niz[] = {1,2,3,4,5};
doSomething(niz);

Mislim da u oba slučaja se salje pokazivač pa je nebitno jel prostor dinamički ili statički alociran sve sto trebas je poslati jos velicinu polja (da nebi pristupali lokacijama kojima ne trebamo) to mozemo uraditi sa sljedecom linijom koda (ili naravno ako vec poznajes velicinu posljes kao argument funkciji).

Code:
sizeof(niz)/sizeof (int) /*u ovom slucaju int jer je tip niza cijeli broj*/

ali samo sa statički alociranim nizom jer compiler ne zna velicinu dinamički alociranog niza (vraća velicinu pokazivaca) , i to je to.

"When all else fails, read the manual."
(This post was last modified: 23-12-2011 05:42 PM by danielvast.)
23-12-2011 05:28 PM
Find all posts by this user Quote this message in a reply
r0tring Offline
Redoviti posjetitelj
**

Posts: 237
Joined: Apr 2009
Reputation: 11
Post: #4
RE: Predavanje niza funkciji
http://www.cplusplus.com/doc/tutorial/arrays/
23-12-2011 07:52 PM
Find all posts by this user Quote this message in a reply
MetalGenius Offline
Novi korisnik
*

Posts: 46
Joined: Oct 2011
Reputation: 3
Post: #5
RE: Predavanje niza funkciji
Hvala vam pogledacu primjere da li rade... hvala puno ^_^ He he

I can't escape myself.
23-12-2011 09:35 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)