Reading floats into an array

后端 未结 6 799
[愿得一人]
[愿得一人] 2021-01-22 00:39

How could I read let\'s say 10 floats and store them in an array without wasting any memory?

6条回答
  •  余生分开走
    2021-01-22 01:30

    sounds like homework.

    read the number of floats from the input. multiply that by the size of an individual float allocate that exact number of bytes storing the address in a pointer to floats have a loop read in the floats from the input have a loop that adds up all the floats in the array

    My guess here is the homework lesson is to realize the connection between the term pointer and array, although you can do this without any array indexing, but your question implies that you have to use an array.

提交回复
热议问题