473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

two dimensional array initialization

Hello everyone,
I find to initialize two dimentional array in Visual Studio, I have to
specify the number of elements. For example,

Expand|Select|Wrap|Line Numbers
  1. const char foo[][] = {"hello",  "world"}; // compile error
  2. const char goo[][64] = {"hello",  "world"}; // compile correct
  3.  
So, the best solution is to specify the number of elements of the 2nd
dimension (inner dimension)?
thanks in advance,
George
Jul 27 '07 #1
2 2335
On Fri, 27 Jul 2007 02:40:06 -0700, George
<Ge****@discussions.microsoft.comwrote:
>Hello everyone,
I find to initialize two dimentional array in Visual Studio, I have to
specify the number of elements. For example,

Expand|Select|Wrap|Line Numbers
  1. const char foo[][] = {"hello",  "world"}; // compile error
  2. const char goo[][64] = {"hello",  "world"}; // compile correct

So, the best solution is to specify the number of elements of the 2nd
dimension (inner dimension)?
Not the "best" solution but "the" solution; that is, it's required. The
compiler needs that information to know how to lay out and access the
array.

--
Doug Harrison
Visual C++ MVP
Jul 27 '07 #2
How to write the code, Doug? Could you let me know your implementation
please? I want to learn better ideas. :-)
regards,
George

"Doug Harrison [MVP]" wrote:
On Fri, 27 Jul 2007 02:40:06 -0700, George
<Ge****@discussions.microsoft.comwrote:
Hello everyone,
I find to initialize two dimentional array in Visual Studio, I have to
specify the number of elements. For example,

Expand|Select|Wrap|Line Numbers
  1. const char foo[][] = {"hello",  "world"}; // compile error
  2. const char goo[][64] = {"hello",  "world"}; // compile correct
  3.  
So, the best solution is to specify the number of elements of the 2nd
dimension (inner dimension)?

Not the "best" solution but "the" solution; that is, it's required. The
compiler needs that information to know how to lay out and access the
array.

--
Doug Harrison
Visual C++ MVP
Jul 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
4
by: Grumble | last post by:
Hello, Is it not legal in C90 to initialize a multi-dimensional array with a one-dimensional initializer as done below? int a = { 1, 2, 3, 4, 5, 6, 7, 8 }; My compiler complains:...
4
by: Richard Hayden | last post by:
Hi, Why does gcc (3.3.2) give me a 'initialization from incompatible pointer type' warning when compiling: int main(int argc, char** argv) { int testa; int** testp = testa; }
9
by: Dadi | last post by:
Hi, I can make a simple initialization work like this: Object ONE_ROW = {{"Vodafone", "5550160100197016"}}; But, now I want to create another array that consists of multiple copies of...
7
by: ashu | last post by:
look at code #include<stdio.h> int *mult(void); int main(void) { int *ptr,i; ptr=mult; for(i=0;i<6;i++) { printf("%d",*(ptr++));
4
by: TG | last post by:
Hi there ! I'm just starting to use Numeric here, and I'm wondering : how can I efficiently initialize every values of a N-dimensional array, given I don't know the number of dimensions ? I'm...
8
by: kd | last post by:
Newbie question here. It's been a while since I've done C programming, and I hit a wall last night. Let's say I have a three dimensional array, like so: int p = {{{0,0,0}, {1,1,1},...
5
by: David T. Ashley | last post by:
Hi, Aside from the obvious recursive syntax for initialization, $x = array( ... array( ...)), what is the best way to deal with multi-dimensional arrays in PHP? It seems there is no...
4
by: Gernot Frisch | last post by:
Hi, I need a class, that has a 4 dimensional array (can be 3 dimensional, too) with such an operator: T operator()(int x1, int x2=0, int x3=0, int x4=0); that can be used as:
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.