2 Dimensional array representation in C

S

Sac

Hello C Gurus,
As I understand C does not differentiate between 1 and
multi dimensional arrays.
All it does is to allocate sequential memory locations
depending on size.
However when A returns the stored value on 1
dimensional array,where as A returns an address on 2 dimensional
array. Does C represent multi dimensional arrays in different way?
Does standard say anything about this behaviour?


Thanks
Sac
 
K

Keith Thompson

Sac said:
As I understand C does not differentiate between 1 and
multi dimensional arrays.
All it does is to allocate sequential memory locations
depending on size.
However when A returns the stored value on 1
dimensional array,where as A returns an address on 2 dimensional
array. Does C represent multi dimensional arrays in different way?
Does standard say anything about this behaviour?


A two-dimensional array is simply an array of arrays, and so forth for
higher dimensions.

There are other ways of representing multidimensional array data. For
example, you can have an array of pointers, each of which points to
the first element of a one-dimensional array. This is more flexible
(you don't have to specify the size when you create it), but also a
bit more difficult to manage.

Recommended reading: Section 6 of the comp.lang.c FAQ,
<http://www-c-faq.com>.
 
C

CBFalconer

Sac said:
As I understand C does not differentiate between 1 and multi-
dimensional arrays. All it does is to allocate sequential memory
locations depending on size. However when A returns the stored
value on 1 dimensional array,where as A returns an address on
2 dimensional array. Does C represent multi dimensional arrays in
different way? Does standard say anything about this behaviour?


See the C-faq, section 6. Also the standard, C99.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://c-faq.com/> (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> (C99)
<http://cbfalconer.home.att.net/download/n869_txt.bz2> (pre-C99)
<http://www.dinkumware.com/c99.aspx> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

n869_txt.bz2 is a bzipped version of n869, the last C99 draft
available in text form.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top