arrays
-
Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this:
int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; ....
Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004) -
Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this:
int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; ....
Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004) -
Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this:
int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; ....
Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)If you are trying to exercize the KISS principle, then just create two different arrays and use your if to determine which to use. If you want to make it dynamic, use a linked list. My code isn't buggy. Those are all fleatures.
-
Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this:
int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; ....
Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)try:
int * myArray = new int[size];
remember to call:delete [] myArray;
when you've finished with it. -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky