Solved

Multidimensional arrays

Posted on 2000-05-03
1
192 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now