Thread: arrrays and while loops

  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,829
    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
    London, United Kingdom
    Posts
    226
    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
Website Security Test