If we can have
Then why can't we haveCode:int MyArray[5] = {1,2,3,4,5};
?Code:int a; int b; int c; int d; int e; int MyArray[5] = {a,b,c,d,e};
The first one compiles fine, but the second doesn't.
If we can have
Then why can't we haveCode:int MyArray[5] = {1,2,3,4,5};
?Code:int a; int b; int c; int d; int e; int MyArray[5] = {a,b,c,d,e};
The first one compiles fine, but the second doesn't.
Heh, that isn't even allowed in C/C++ last I checked. I remember there being a reason they couldn't do it that way, though it escapes me.
AGN's Resident Zelda Classic Developer and Sonic the Hedgehog Fanboy
Oh, right ok.
Fair enough.
So
is the most efficient method?Code:int a; int b; int c; int d; int e; int MyArray[5]; MyArray[0] = a; MyArray[1] = b; //etc.
That will work, but I don't think it's going to do what you think it's going to do.
(wait...what did I just say? )
What I mean is, if you do that, and then do something likeyour array is not going to change - there is no "link" between the integer "a" and your array. So unless you are going to be constantly updating "a", "b" ... "e" and then pushing those values in to your array as in your snippet above, there's really no reason to declare/use the "a", "b" ... "e" variables. Just modify your array directly.Code:a = 10;
What I think it's going to do is load some integers into an array.
I have arguments in an ffc, and I want to load them into an array so I don't have to write out four lots of code.
I know the array's not going to change, I only want to set it once.
Gotcha.
On an interesting side note, evidently you can only use positive numbers when you initialize an array at declaration. The following fails to compile (at least in build 819)...You get an error on the minus sign.Code:int MyArray_1[5] = {0, 1, 2, -3, 4};
Might be linked to the fact that we can't declare negative constants?
There are currently 1 users browsing this thread. (0 members and 1 guests)