Solved

Multidimensional arrays

Posted on 2000-05-03
1
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

617 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