使用new进行动态初始化时内存重叠 [英] memory overlap while dynamic initialization using new

查看:80
本文介绍了使用new进行动态初始化时内存重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,用于计算数字中的数字总和

。 432567

sum = 4 + 3 + 2 + 5 + 6 + 7 = 27

this is my code to calculate the sum of digits in a number
for eg. 432567
sum =4+3+2+5+6+7=27
i ''m using turboc++ compiler from borland and i ''m runing my program on DOS.

展开 | 选择 | Wrap | 行号

推荐答案

你没有为quo和rem分配足够的空间。您需要选择一些比您希望处理的最大位数更大的数字。


我的编译器不会让我说新的... []没有数字在[和]之间。我不确定创造了什么,但还不够。由于您只是在本地使用变量,因此可以在本地定义它们。例如:int quo [20];
You''re not allocating enough space for quo and rem. You need to pick some number that is greating than the max number of digits you expect to process.

My compiler won''t let me say new ... [ ] without a number in between the [ and ]. I''m not sure what is being created, but its not enough. Since you''re just using the variables locally, you can define them locally. For example: int quo[20];



你没有为quo和rem分配足够的空间。您需要选择一些比您希望处理的最大位数更大的数字。


我的编译器不会让我说新的... []没有数字在[和]之间。我不确定创造了什么,但还不够。由于您只是在本地使用变量,因此可以在本地定义它们。例如:int quo [20];
You''re not allocating enough space for quo and rem. You need to pick some number that is greating than the max number of digits you expect to process.

My compiler won''t let me say new ... [ ] without a number in between the [ and ]. I''m not sure what is being created, but its not enough. Since you''re just using the variables locally, you can define them locally. For example: int quo[20];



i认为将动态分配给数组的语法如下:

数据类型指针=新数据类型[];

例如:

int * p = new int [];

如果我动态分配内存我认为大小不固定,总是决定于运行时间如此,我不能拒绝。在[]。

我们可以使用指针p访问动态分配的内存;

关于quo [20],这是在编译时分配内存。我想要使用在运行时分配的变量,而变量将依赖于运行时的数值。


i认为它与我们用于的内存模型有关,例如:tiny ,小,紧凑,巨大等。

i think the syntax to allocate memeory to an array dynamically is as follows:
datatype pointer = new datatype[];
eg:
int *p = new int[];
if i am allocating memory dynamically i think the size is not fixed, it is always decided at run time so, i can''t put a no. inside [].
we can access the dynamically allocated memory using pointer p;.
about quo[20],this is allocation of memory at compile time.i want to use a variable allocated at the run time which in turn will be dependent on value of the number at run time.

i think it is related to the memory model we are using for eg: tiny,small,compact,huge etc.



数据类型指针=新数据类型[];

例如:

int * p = new int [];
datatype pointer = new datatype[];
eg:
int *p = new int[];



没有在C ++中动态分配内存的语法


数据类型指针=新数据类型[表达式];


例如:

No the syntax to dynamically allocate memory in C++ is

datatype pointer = new datatype[expression];

eg:

展开 | 选择 | Wrap | 行号


这篇关于使用new进行动态初始化时内存重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆