Thread: Returning Multi dimension array

  1. #16
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by Elysia View Post
    Secondly, as we've told you: a 2D array isn't a pointer.
    Just wanted to clarify something here, isn't the name of an array a pointer to the first/zeroeth element.
    Only difference for multi-dimensional arrays is that it's a pointer to an array instead of a pointer to a type.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It decays to a pointer to its first element, yes.
    And yes, you could say that 2D arrays decays into a pointer to an array.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by C_programmer.C View Post
    than can't i return a two dimensional array to main in my code?
    A function can't return an array, but it can return a pointer to a one/multi-dimensional array.
    Look at the post by Bayint Naung for a function that returns a pointer to an array of N ints.

  4. #19
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    Okay thank you very much!
    I might be looking for help in another topic soon!

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by itCbitC View Post
    Just wanted to clarify something here, isn't the name of an array a pointer to the first/zeroeth element.
    No, it's not a pointer. You cannot do this:
    Code:
    int array[ X ];
    array++;
    If it was a pointer, you could do that. You can't, it's not.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #21
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    2.5: How can an array be an lvalue, if you can't assign to it?

    The ANSI C Standard defines a "modifiable lvalue," which an array is not.
    Arrays and pointer

  7. #22
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by quzah View Post
    No, it's not a pointer. You cannot do this:
    Code:
    int array[ X ];
    array++;
    If it was a pointer, you could do that. You can't, it's not.


    Quzah.
    JTC! I meant the conversion of an array name to a pointer when it is passed to or returned from a callee.
    Perhaps this may quench your thirst - A question about pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Help printing a multi array
    By cjohnman in forum C Programming
    Replies: 4
    Last Post: 05-05-2008, 01:35 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Passing a 2 dimension array to a function
    By Chuck in forum C++ Programming
    Replies: 8
    Last Post: 12-09-2002, 09:42 AM
  5. multi array to function
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-09-2001, 03:01 AM