SteveW
Member
Registered: 15th Jul 02
Location: Up in the clouds
User status: Offline
|
OK heres the problem:
What 3 things need to be written to declare an array???
What 2 things need to be written to access an element of an array???
Cheers peeps.
Steve
|
m-dot
Member
Registered: 17th Aug 03
Location: Warrington
User status: Offline
|
Declare the array arrays size and the type of elements. All elements must be the same type. Write the element type name, the name of the array variable, then the size enclosed in square brackets ("[]").
int scores[100]; --- array of 100 ints, scores[0] to scores[99]
char name[40]; --- array of 40 chars, name[0] to name[39]
You need three pieces of information to gain access to an array element:
1. The starting address of the array or base address.
2. The array element number or array index you wish to access.
3. The data type size, in bytes, of the data type stored in the array. The size of the data type, along with the index, will be used to calculate an offset into the array from the address of the first element using the following formula:
address of array element = base address + (data type size * array index)
|
CORSA NUT
Member
Registered: 3rd Aug 01
Location: Wirral
User status: Offline
|
WTF!!!!!
|
SteveW
Member
Registered: 15th Jul 02
Location: Up in the clouds
User status: Offline
|
SXI07 - your a life saver, just found all that on a site myself actually. Well done, spot on matey.
Stay online for a bit, need some other bits answered as well
Steve
|
SteveW
Member
Registered: 15th Jul 02
Location: Up in the clouds
User status: Offline
|
Here you are try these:
What are the allowable index values for the array MARKS???
What is necessary to initialise all elements of the array to zero???
Cheers buddy
Steve
|
Adam-D
Member
Registered: 11th May 02
Location: Cheshire
User status: Offline
|
fuvkin hate c++
|
Ben
Banned
Registered: 12th Jan 03
Location: West Yorkshire
User status: Offline
|
what is it
|
Tim
Site Administrator
Registered: 21st Apr 00
User status: Offline
|
1) A definition of the array MARKS might help answer the question? If you mean the range of values, then it's just ( array size - 1 ) i.e. int marks[100] would have values 0 - 99.
2) To initialise everything to zero, just do
int marks[100] = {0};
[Edited on 27-08-2003 by Tim]
|
m-dot
Member
Registered: 17th Aug 03
Location: Warrington
User status: Offline
|
lol, you got me on the first one! but if you want to initialise an array to all zeros, initialise it with single zeros:
char cArray[100]={0};
|
m-dot
Member
Registered: 17th Aug 03
Location: Warrington
User status: Offline
|
bastard, tim replied quicker
|
m-dot
Member
Registered: 17th Aug 03
Location: Warrington
User status: Offline
|
tim check your mails
|
neiliosxi
Member
Registered: 17th Dec 02
Location: Teesside (NE)Drives: Megane R26
User status: Offline
|
I had to learn all this at uni, 1st year on electrical engineering degree, its a nightmare if u have never heard of C++!!!
|
SteveW
Member
Registered: 15th Jul 02
Location: Up in the clouds
User status: Offline
|
Great, but why would it be necessary to do this??
Steve
|
m-dot
Member
Registered: 17th Aug 03
Location: Warrington
User status: Offline
|
lol sorry, forgot your question: a loop is used to initialise the whole array to zero, thus even if the array size increases, the main loop code still remains the same. All that would change is the constant iSIZE.
|
Richie
Member
Registered: 3rd Dec 02
Location: Newport, Wales
User status: Offline
|
Steven stop cheating
|
m-dot
Member
Registered: 17th Aug 03
Location: Warrington
User status: Offline
|
lol steve are you doing course work or something? right, thats it.. no more help for you
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
No he's playing with C++ for fun
|
m-dot
Member
Registered: 17th Aug 03
Location: Warrington
User status: Offline
|
he might be
|
SteveW
Member
Registered: 15th Jul 02
Location: Up in the clouds
User status: Offline
|
you got me
Cant get my head round this shite
Steve
|
corb
Member
Registered: 24th Apr 02
Location: Calgary, Alberta, Canada
User status: Offline
|
What is it?
|
corb
Member
Registered: 24th Apr 02
Location: Calgary, Alberta, Canada
User status: Offline
|
And have u got any pics of Hels install anywhere?
|