473,395 Members | 1,535 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,395 software developers and data experts.

char *dic[][40]={"i","love","c++","",""};

hedonplay
Please explain this declaration in details
it makes confusing!
Apr 14 '07 #1
3 1472
JosAH
11,448 Expert 8TB
Please explain this declaration in details
it makes confusing!
Have you tried to compile and run it? Add the following statement and see what
the output is:
Expand|Select|Wrap|Line Numbers
  1. // assuming C++
  2. for (int i= 0; i < 5; i++)
  3.    cout << i << ": " << dic[i] << endl;
I'm sure this is not what you wanted. Hint: remove the '*' in your definition of 'dic'.
You have declared an array with an unknown number of rows (the initializer will
determine how many rows are needed. Every row contains 40 pointers to chars
of which you initialize only five. The iniitializer tells the compiler that only one
row is needed.

kind regards,

Jos
Apr 14 '07 #2
thank you !
But what's the comma' s function?
Apr 14 '07 #3
JosAH
11,448 Expert 8TB
thank you !
But what's the comma' s function?
I separates the element in the initializer list; that's how C and C++ defined the
syntax for intializer lists. e.g.
Expand|Select|Wrap|Line Numbers
  1. int a[]= { 1, 2, 3 };
  2. char* b[]= { "foo", "bar", "baz" };
  3. double c[]= { 3.1415, 2.71, 1.69 };
The arrays above will all be initialized with three elements.

kind regards,

Jos
Apr 14 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.