<<< Standard Library swap algoritm     Index     Two-dimensional Array >>>

14. Array as Function Argument

  • 
    #include <iostream>
    using namespace std;
    void foo( double dbls[] )
    {
        cout
            << "in foo() size of dbls is "
            << sizeof( dbls )
            << '\n'
            ;
    }
    int main()
    {
        double dummy[ 4 ] = { 0 };
        cout
            << "in main() size of dummy is "
            << sizeof(dummy)
            << '\n'
            ;
        foo( dummy );
        return 0;
    }
    /* Program output:
    in main() size of dummy is 32
    in foo() size of dbls is 4
    */
    
    
  • The size of an array is not available to the called function.

  • No matter what is the array type, function argument is simply a constant address of the initial element of the array.

  • Array differs from all other C++ types in such way that array is not (and cannot be) passed to a function by value!

<<< Standard Library swap algoritm     Index     Two-dimensional Array >>>