samedi 25 novembre 2017

I can't return array from function

I want to function(fun) take a number from the int main() and use it in function then return a array;please help

#include<iostream>
using namespace std;

int *fun(int s)
{
   static int arr[100];
   arr[0] = s;
   arr[1] = 20;

   return arr;
}

int main()
{
    int s=10
    int *ptr = fun(int s);
    cout << ptr[0] << " " << ptr[1];
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire