【问题标题】:Dynamic memory Pointers动态内存指针
【发布时间】:2017-06-03 01:42:39
【问题描述】:
int main(int argc, char **argv) {
    float *rainfall;
    float rain_today;
    // rainfall has been dynamically allocated space for a floating point number.
    // Both rainfall and rain_today have been initialized in hidden code. 
    // Assign the amount in rain_today to the space rainfall points to.

    return 0;
}

大家好。这是一个非常基本的问题,但我还没有找到解决方案。 不就是一个

rain_today = *rainfall

【问题讨论】:

  • 反之亦然。

标签: c pointers memory dynamic


【解决方案1】:

没有。

rain_today = *rainfall; 将采用rainfall 指向的值并将其放入rain_today(理想情况下为NULL)。

您被要求做的是将rain_today 的值放入指针rainfall 指向的空间中

这是:

*rainfall = rain_today \\the value of rain_toady is COPIED to the space pointed by rainfall

或者你可以这样做:

rainfall = &rain_today \\rainfall points at the memory location of rain_today

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 2019-07-12
    • 2015-02-05
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多