initializing a multi-dimensional array topic posted under C++ Programming which is a part of Programming category in CFanatic Forum

09-30-2006, 04:56 AM
|
|
Junior Member
|
|
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
initializing a multi-dimensional array
I can do this
double T[2][3] = { {1,3,4},{7,8,9}};
but not this
double T[2][3];
T = { { a,b,c} , {d,e,f} }
Why is that? Will I have to assign T[?][?] 6 times to do this? any better ways to do this assignment?
Thanks,
--j
|

03-29-2007, 08:17 AM
|
|
Junior Member
|
|
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Re: initializing a multi-dimensional array
Initializing Multidimensional Arrays
You can also initialize multidimensional arrays. You assign the list of values to array elements
in order, with the last array subscript changing while each of the former hold steady.
Therefore, if you have the following array, the first three elements go into theArray[0]; the
next three into theArray[1]; and so on:
int theArray[5][3];
You initialize this array by writing
int theArray[5][3] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
11
For the sake of clarity, you could group the initializations with braces, as in the following
example:
int theArray[5][3] = { {1,2,3},
{4,5,6},
{7,8,9},
{10,11,12},
{13,14,15} };
The compiler ignores the inner braces, which make it easier to understand how the numbers
are distributed.
Each value must be separated by a comma, without regard to the braces. The entire
initialization set must be within braces, and it must end with a semicolon.
Listing 11.5 creates a two-dimensional array. The first dimension is the set of numbers from
0 to 5. The second dimension consists of the double of each value in the first dimension.
or VECTORS
|
|
The Following User Says Thank You to hl2mods.info For This Useful Post:
|
|

04-18-2009, 11:15 AM
|
|
Junior Member
|
|
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Re: initializing a multi-dimensional array
I never reply while browsing forums but I'm already pissed off. C'MON people... start THINKINGe! 99% of your ANSWERS is just a junk, nothing more!!!
hl2mods.info - go to hell, your post is shit and spam. Read the first post once more. He asked how to assign multiple values at once to multi-dimensional array AFTER creating it.
learn to use your brain, all of you.
peace
Ahh and I dont care about post's date. If even 1 person starts using his brain after reading this, it's a success.
|
|
The Following User Says Thank You to tehtehghost For This Useful Post:
|
|

04-22-2009, 08:10 AM
|
|
Junior Member
|
|
Join Date: Oct 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: initializing a multi-dimensional array
Quote:
Originally Posted by tehtehghost
I never reply while browsing forums but I'm already pissed off. C'MON people... start THINKINGe! 99% of your ANSWERS is just a junk, nothing more!!!
hl2mods.info - go to hell, your post is shit and spam. Read the first post once more. He asked how to assign multiple values at once to multi-dimensional array AFTER creating it.
learn to use your brain, all of you.
peace
Ahh and I dont care about post's date. If even 1 person starts using his brain after reading this, it's a success.
|
Dear Sir,
There some people who at least try to help. But you are not helping. More over, you are inspiring him not to help again.
If you thing hl2mods.info is wrong answer the right one or just go to hell and dont bother those people.
This site needs people who want to answer. This site definitly do not need those people who think they know but wont answer. so please just go to hell live with satan and never come back
|

09-09-2009, 05:27 AM
|
|
Junior Member
|
|
Join Date: Sep 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: initializing a multi-dimensional array
I second the mOtion..
|

12-04-2009, 01:27 AM
|
|
Junior Member
|
|
Join Date: Oct 2009
Location: United States
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
initializing a multi dimensional array
coercing maybe
wow seems a very interesting conundrum ... and i thought i had it bad with multi-dimensional hashes ... just curious but why do you want to do this for anyway?
|

04-09-2011, 09:41 AM
|
|
Junior Member
|
|
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: initializing a multi-dimensional array
if a b c d are variables then that assignment should work else if you were trying to assign characters then you need '' for single characters and "" for string however for strings you would need a different data type and a different means of initilising
so 'a' will initialise the array with the numerical value associated with a, there are no letters in computing only numbers 0 and 1
ps the cake is a lie
|

09-13-2011, 07:44 PM
|
|
Junior Member
|
|
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: initializing a multi-dimensional array
post the multi dimention arry program guys
|

11-20-2011, 02:52 AM
|
 |
Junior Member
|
|
Join Date: Oct 2011
Location: london
Posts: 13
Thanks: 0
Thanked 6 Times in 5 Posts
|
|
Re: initializing a multi-dimensional array
Everyone please stop fighting !!! we are all here to help!!!
The reason why you are not getting is that double is meant only for long integers and not characters!!! if you want to initialize characters then do the following:
char T[2][3]={{a,b,c},{d,e,f}};
Now it will work perfectly!!!! Hope this helped you!!!
|
|
The Following User Says Thank You to ophelia.2010 For This Useful Post:
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
All times are GMT -5. The time now is 03:08 PM.
|