Solved

Multidimensional arrays

Posted on 2000-05-03
1
195 Views
Last Modified: 2010-04-15

 Hi.

 How to initialize an array of arrays of ints ?consider the following
sentence:

 int  *numbers[2]  ={
                               { 1 ,2 ,3},
                               {1 ,2 ,3 ,4}
                              };


Here {1 ,2 ,3} and {1 ,2 ,3 ,4} are arrays of integers containing
3 and 4 items respectively and "numbers" is supposed to be an array
of (2) arrays of integers ,but this solution does not work.What
should I do ?
0
Comment
Question by:e6694811
1 Comment
 
LVL 16

Accepted Solution

by:
imladris earned 45 total points
ID: 2773790
You can only initialize into space that the compiler can reserve statically at compile time. The declaration for your numbers array only allocates two slots in memory for two integer pointers. You must reserve the space for the arrays with the actual numbers first. It could be done something like:

int num1[3] = { 1, 2, 3 };
int num2[4] = { 1, 2, 3, 4 };
int *numbers[2] = { num1, num2 };
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C#, VS15, StructLayout 1 135
C language IDE – Compilers installation 14 78
How to jump to matching brace in eclipse editor ? 1 353
Global Keyboard Hooks Blocked 4 88
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question