Return array in a function

后端 未结 19 2303
清酒与你
清酒与你 2020-11-22 05:23

I have an array int arr[5] that is passed to a function fillarr(int arr[]):

int fillarr(int arr[])
{
    for(...);
    return arr;
         


        
19条回答
  •  渐次进展
    2020-11-22 05:55

    i used static array so that while returning array it should not throw error as you are returning address of local variable... so now you can send any locally created variable from function by making it as static...as it works as global variable....

    #include
    using namespace std;
    
    char *func(int n)
    {
       // char a[26]; /*if we use this then an error will occur because you are 
                            //  returning address of a local variable*/
        static char a[26];
        char temp='A'; 
        for(int i=0;i

提交回复
热议问题