Is it possible to allocate array inside function and return it using reference?

后端 未结 3 1219
离开以前
离开以前 2020-12-02 01:14

I\'ve tried using a tripple pointer, but it keeps failing. Code:

#include 
#include 

int set(int *** list) {
  int count, i;
         


        
3条回答
  •  醉梦人生
    2020-12-02 01:37

    As far as I understand your question you want to return an array which is allocated in another function : here is the simple version of this

    #include
    #include
    int* set(int *list) {
      int count, i;
      printf("Enter number:\n");
      scanf("%d", &count);
      list = (int *) malloc ( sizeof (int) * count);
    
      for ( i = 0; i

提交回复
热议问题