arrrays and while loops

This is a discussion on arrrays and while loops within the C++ Programming forums, part of the General Programming Boards category; hello reader, i have a question which has been buggin me ok, we have an array of type int which ...

  1. #1
    chuckles
    Guest

    arrrays and while loops

    hello reader, i have a question which has been buggin me
    ok,

    we have an array of type int which hasnt completely been filled
    thus using a while or do while loop
    how could i print out the contents of it only.... within another
    function?
    The array is within another function....

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Pass the array to the printing function as a parameter.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    Munich, Germany
    Posts
    224
    Pass the array and the number of elements in the array to the other function as a parameter.

    As far as i know, there is no standard function for determination of no. of element in an array in C/C++.

    e.g.

    // only six elements in the array
    .
    .
    int a[10] = {1,2,3,5,7,2};
    print_the_array(&a[0],6);
    .
    .
    void print_the_array(int *array,int n)
    {
    for (int i=0;i!=n;i++) cout << array[i] << endl;
    }

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21