Hey, what's going on?

Returning Array from a Function in C++ (using pointer)

Posted by Syeilendra Pramuditya on April 17, 2014

/*
Returning Array from a Function in C++ (using pointer)
Source: http://stackoverflow.com/questions/3473438/c-return-array-in-a-function
*/
#include <iostream>
using namespace std;

int * fill_array(int array1[],int n){
int i;
    for (i=0;i<n;i++){
    array1[i]=3*i;
    }
return(array1);
}

int main(){
int const n=5;
int * array1;
int i,a[5];
array1=fill_array(a,n);

    for (i=0;i<n;i++){
    cout<<array1[i]<<endl;
    }

}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: