array of arrys

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

Many thanks to Santosh with that link to a simpler descibed k&r2. I'm
learning slowly.

But here's the question:

int [3][7];

A two dimensional array says three something are arrays of type int each
containing arrays of 7 elements. What about the first dimension [3]? Is it
type int too?

Bill
 
K

Keith Thompson

Bill Cunningham said:
Many thanks to Santosh with that link to a simpler descibed k&r2. I'm
learning slowly.

But here's the question:

int [3][7];

A two dimensional array says three something are arrays of type int each
containing arrays of 7 elements. What about the first dimension [3]? Is it
type int too?

In C, a two dimensional array is exactly the same thing as an array of
arrays. If you understand C arrays (which is no small feat in
itself), then everything about multidimensional arrays follows from
that.

The above declaration doesn't actually declare anything. I think what
you meant was:

int array_object[3][7];

array_object itself is of type "array 3 of array 7 of int". It's an
array consisting of 3 elements; each element is of type "array 7 of
int". Each element of each element of array_object is of type int.

(The indices can be of any integer type. The index type isn't part of
an array type; only the length of each dimension is.)

If you haven't already done so, take a look at the comp.lang.c FAQ,
<http://www.c-faq.com/>, particularly section 6.
 
S

santosh

Bill said:
Many thanks to Santosh with that link to a simpler descibed k&r2.
I'm
learning slowly.

But here's the question:

int [3][7];

A two dimensional array says three something are arrays of type int
each containing arrays of 7 elements. What about the first dimension
[3]? Is it type int too?

In addition to Keith excellent answer I also recommend downloading and
playing around with a nifty little program called 'cdecl'. It knows a
lot about C syntax and can translate a C declaration to an English
description or vice versa. It should be in pure ISO C and hence should
compile with minimal fuss on all systems with a conforming compiler.

Get a package from:

<http://linux.maruhn.com/sec/cdecl.html>

And here is the manpage:

<http://linuxcommand.org/man_pages/cdecl1.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top