Article View: alt.comp.lang.learn.c-c++
Article #281Re: Pointer and Array?
From: Victor Bazarov
Date: Tue, 28 Mar 2000 00:00
Date: Tue, 28 Mar 2000 00:00
26 lines
1482 bytes
1482 bytes
"The Incubus" <incubus@securax.org> wrote...
> Well, just, how can I change an array in the main() from a function?
You have to pass it into that function, I suppose.
#include <iostream>
void change_array_member(int a[], size_t length, size_t whichone, int
newvalue)
{
if (whichone < length)
a[whichone] = newvalue;
}
int main()
{
int myarray[10] = { 1,2,3,4,5,6,7,8,9,10 };
change_array_member(myarray, 10, 5, 77);
std::cout << myarray[5] << std::endl;
}
Victor
--
Please remove capital A's from my address when replying by mail
Technical Details
Message-ID:
<8brn52$cn2$1@bob.news.rcn.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<Ty4E4.45492$ds6.95252@afrodite.telenet-ops.be> <38E0D8C7.4C0E5B4F@pandora.be> <hp5E4.45724$ds6.96460@afrodite.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 100a19,56cfd2038e773edf X-Google-Attributes: gid100a19,public X-Google-Thread: fcea4,56cfd2038e773edf X-Google-Attributes: gidfcea4,public X-Google-Thread: 114592,56cfd2038e773edf X-Google-Attributes: gid114592,public From: "Victor Bazarov" <vAbazarov@dAnai.com> Subject: Re: Pointer and Array? Date: 2000/03/28 Message-ID: <8brn52$cn2$1@bob.news.rcn.net> X-Deja-AN: 603668026 References: <Ty4E4.45492$ds6.95252@afrodite.telenet-ops.be> <38E0D8C7.4C0E5B4F@pandora.be> <hp5E4.45724$ds6.96460@afrodite.telenet-ops.be> X-Priority: 3 X-Mimeole: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: abuse@rcn.com X-Trace: Gcy96hEuiGAnfBi01yIgtljSkrWsJVMWKFeZ/AUorbE= X-MSMail-Priority: Normal NNTP-Posting-Date: 29 Mar 2000 01:44:02 GMT Newsgroups: alt.comp.lang.learn.c-c++,be.comp.os.linux,be.comp.programming