dynamic memory allocation and dynamic array

前端 未结 2 1331
孤城傲影
孤城傲影 2020-12-22 13:16

I need to write a program, that will ask a user to enter a number of how many ints they would like to enter.. so the output would look like

Enter number of Ints (mus

相关标签:
2条回答
  • 2020-12-22 13:54

    After you read numInts, you allocate the array like so:

    int* arr = malloc(numInts*sizeof(int));
    

    Now you populate the array with your already existing function and assigning the values read to the array.

    I'm not going to give you a full solution, since this is homework and wouldn't help you, but you access the i'th element of the array with the [] operator:

    arr[i];
    
    0 讨论(0)
  • 2020-12-22 13:57

    Learn more about pointers and calloc

    0 讨论(0)
提交回复
热议问题