CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

initializing a multi-dimensional array topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2006, 04:56 AM
Junior Member
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
John is on a distinguished road
| More
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
Reply With Quote
  #2  
Old 03-29-2007, 08:17 AM
Junior Member
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
hl2mods.info is on a distinguished road
| More
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
Reply With Quote
The Following User Says Thank You to hl2mods.info For This Useful Post:
Hassan Akhtar (09-16-2011)
  #3  
Old 04-18-2009, 11:15 AM
Junior Member
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
tehtehghost is on a distinguished road
| More
Thumbs down 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.
Reply With Quote
The Following User Says Thank You to tehtehghost For This Useful Post:
Hassan Akhtar (09-16-2011)
  #4  
Old 04-22-2009, 08:10 AM
Junior Member
 
Join Date: Oct 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
johny_1015_1981 is on a distinguished road
| More
Re: initializing a multi-dimensional array

Quote:
Originally Posted by tehtehghost View Post
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
Reply With Quote
  #5  
Old 09-09-2009, 05:27 AM
Junior Member
 
Join Date: Sep 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
LuciferiA is on a distinguished road
| More
Re: initializing a multi-dimensional array

I second the mOtion..
Reply With Quote
  #6  
Old 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
Latduppy73 is on a distinguished road
Send a message via ICQ to Latduppy73
| More
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?
Reply With Quote
  #7  
Old 04-09-2011, 09:41 AM
Junior Member
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
JonRambo is on a distinguished road
| More
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
Reply With Quote
  #8  
Old 09-13-2011, 07:44 PM
Junior Member
 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
mujahid ahmed is on a distinguished road
| More
Re: initializing a multi-dimensional array

post the multi dimention arry program guys
Reply With Quote
  #9  
Old 11-20-2011, 02:52 AM
ophelia.2010's Avatar
Junior Member
 
Join Date: Oct 2011
Location: london
Posts: 13
Thanks: 0
Thanked 6 Times in 5 Posts
ophelia.2010 is on a distinguished road
| More
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!!!
Reply With Quote
The Following User Says Thank You to ophelia.2010 For This Useful Post:
shabbir (11-20-2011)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
1-dimensional array type double.....and....2-dimensional array styles8687 C++ Programming 2 01-01-2009 04:30 AM
C char array help! Dylan C Programming 1 07-31-2008 04:45 PM
Reset array coderzone C# Programming 1 03-11-2008 11:25 PM
multi byte to wide char converting problem(Related to Unicode) rajeshgalla C Programming 0 10-10-2007 09:00 AM
multi-tier applications fly C# Programming 0 09-28-2007 07:46 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:08 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board