declaring arrays
Moderator: Coders of Rage
declaring arrays
I am reading a c++ book, and it doesn't go into detail on how to change the whole array after it has been declared for example myArray[10] {0,1,2,3,4,5,6,7,8,9} wont work, how is this done?
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: declaring arrays
Example:Randi wrote:I am reading a c++ book, and it doesn't go into detail on how to change the whole array after it has been declared for example myArray[10] {0,1,2,3,4,5,6,7,8,9} wont work, how is this done?
Code: Select all
int Array[10]; //Declares an array with 10 ints
Array[0] = 12; //Arrays start with 0 not 1
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: declaring arrays
Initialization lists can only be used when you first declare the array. If you want to set the entire contents of the array you have to either use a loop as david suggested, or initialize another array with the desired contents and assign it to the original array.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!