Solved

Multidimensional arrays

Posted on 2000-05-03
1
191 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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

763 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

9 Experts available now in Live!

Get 1:1 Help Now