gpt4 book ai didi

c++ - 需要帮忙。 C++ Z :\Dynamic Allocation. cpp(18):错误 C2440: '=':无法从 'int' 转换为 'int *'

转载 作者:行者123 更新时间:2023-11-28 07:27:20 25 4
gpt4 key购买 nike

<分区>

//两个城镇之间的距离是 380 公里。一辆汽车和一辆卡车同时从两个城镇出发。两辆车以什么速度行驶,如果汽车的速度比卡车的速度快 5 公里,我们知道他们在 4 小时后相遇?在计算和显示所需信息时使用动态内存分配和指针。

// The distance between two towns is 380km. A car and a lorry started from the two towns at the same time. At what speed drove the two vehicles, if the speed of the car is with 5km\ faster than the speed of the lorry and we know that they met after 4 hours? Use Dynamic Memory Allocation and Pointer in calculating and Displaying the needed info.

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>

int main ()
{
int t=4;
int d=380;
int dt=20;
int dd;
int * ptr;
int * ptr2;
ptr = (int*) malloc (500*sizeof(int));
ptr2 = (int*) malloc (500*sizeof(int));
dd=d-dt;
ptr = dd/8;
ptr2 = ptr+5;
cout << " The Speed of the Car is: " << ptr << endl;
cout << " The Speed of the Lorry is: " << ptr2 << endl;
return(0);
}

我该如何运行?如何在所有变量中使用动态内存分配?谢谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com