Array of C structs

后端 未结 4 1590
面向向阳花
面向向阳花 2021-01-16 10:54

If I create a struct in C and want to add them to an array that is not set to a fixed size, how is the array created?

Can one create a tempStruct which is used on ev

4条回答
  •  梦毁少年i
    2021-01-16 11:49

    the C array must be with fixed size this is what we have learned years ago but memory allocation functions may help you to find a solution

    in c++ you can use the operator new

    int num=0;
    cout<<"please enter the number"<>num;
    int *x=new int[num];
    for(int i=0;i>x[i];
    }
    //do your work
    

    and as

    Mr Fooz

    mentioned delete[] is used to free the memory allocated by new[] and this is a general example

提交回复
热议问题