Thread: How to pass pointer of 2d array to function

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I was taught that the array name is a pointer to the array. If its not then why can we access an array using a pointer of arrays name?
    O_o

    You were taught with, at best, misleading language.

    An array is an array.
    A pointer is a pointer.

    The identifier, the variable name, of an array may be used where a compatible pointer is expected because the standard requires the behavior of the array being implicitly converted to the compatible pointer. We largely speak of the array "decaying" into a pointer because the array has behavior a real pointer does not exhibit.

    You can explore this yourself by adding a compatible pointer, `sizeof', and "address of" (&) to your test.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  2. #17
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Quote Originally Posted by 3DT View Post
    I was taught that the array name is a pointer to the array. If its not then why can we access an array using a pointer of arrays name?
    As I understand it, there is an equivalence in the notation between pointers and arrays, and an array name will be a pointer to it's first element. But an array is a series of contiguous memory types, and a pointer doesn't have to be.

    It's sort of like, all goldfish are fish, but not all fish are goldfish.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pass pointer to function
    By markucd in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 01:18 PM
  2. pass the pointer of a two dimension array to a function
    By SoFarAway in forum C Programming
    Replies: 8
    Last Post: 04-13-2005, 05:43 AM
  3. Replies: 6
    Last Post: 11-29-2004, 08:50 AM
  4. A pointer to a character pointer array... can't pass
    By Lynux-Penguin in forum C Programming
    Replies: 9
    Last Post: 10-12-2003, 10:53 PM
  5. Replies: 3
    Last Post: 04-02-2002, 01:39 PM

Tags for this Thread