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
Solved

Multidimensional arrays

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Console based application in Linux 1 92
Global Keyboard Hooks Blocked 4 81
C Programming - If Statement 8 82
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 56
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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

791 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