Program for Array name as a pointer - second example


    #include <iostream.h>
    #include <conio.h>
    void main ()
    {
        void multiply_by_2 ( int a[] ) ;
        int array[5] = { 11, -2, 30, 41, 15 } ;
        int *start, *end ;
        clrscr () ;
        multiply_by_2 ( array ) ;/* name of the array is passed to function */
        start = array ;
        end = array + 5 ;
        cout<<"The array elements are....." ;
        for ( ; start < end ; start++ )
            cout<<*start<<endl;
        getch () ;
    }
    void multiply_by_2 ( int a[] )
    {
        int i ;
        for ( i = 0; i < 5; i++ )
            a[i] = a[i] * 2 ;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|