大家好 [英] hi all

查看:92
本文介绍了大家好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


这是Prashant ....我是一个新的工作人员....

我有些困惑....可以我们在运行时更改数组的大小....如果

那么,那么如何使用b $ b请让我知道答案

thanx

hello,

Ths is Prashant....i am a new joinee....
I hv some confusion....can we change the size of array in runtime....if
so,then how

pls let me knw the answer

thanx

推荐答案

prashu写道:
你好,
我有些困惑....我们可以在运行时更改数组的大小....如果
所以,然后如何

请让我知道答案

thanx
hello,

Ths is Prashant....i am a new joinee....
I hv some confusion....can we change the size of array in runtime....if
so,then how

pls let me knw the answer

thanx




一句话:寻找有关的信息realloc。


亲切的问候。


免责声明:

建议的解决方案无效如果你在嵌入式系统工作,你是

UNIVAC或曼彻斯特婴儿电脑的程序员

用于洗碗机,如果你不测试它,并且,一般来说,它根本不是有效的b $ b。此外,它确定不是标准的,并且未定义

行为。



In a single word: look for information about "realloc".

Kind regards.

DISCLAIMER:
The proposed solution could not be valid if you are a programmer of the
UNIVAC or Manchester''s Baby computer, if you work for embedded systems
for dishwashers, if you do not test it, and, in general, it is not
valid at all. Moreover, it is sure that is not standard, and undefined
behaviour.


prashuaécrit:
prashu a écrit :
我有些困惑....我们可以在运行时更改数组的大小....如果


ITYM''''

那么,那么如何
I hv some confusion....can we change the size of array in runtime....if
ITYM ''have''
so,then how




如果它是用malloc()分配的,是的,使用realloc()。这不是常见问题吗?


您还应该考虑链接列表。


-

A +


Emmanuel Delahaye



If it was allocated with malloc(), yes, using realloc(). Isn''t it a FAQ ?

You should also consider linked lists.

--
A+

Emmanuel Delahaye


Emmanuel Delahaye写道:
Emmanuel Delahaye wrote:
如果分配了malloc(),是的,使用realloc()。


或分配另一个realloc,这是最实用的批次

的情况:


void foo (无效)

{


char * a = NULL;

int max_elems = 0;

while(...)

{

...

/ *增加尺寸* /

max_elems ++;

a = realloc(a,max_elems);

...

}


您还应该考虑链接列表。
来自标准:
If it was allocated with malloc(), yes, using realloc().
Or allocated with another realloc, that is the most practical in lots
of situations:

void foo ( void )
{

char *a=NULL;
int max_elems=0;

while(...)
{
...
/* increase size */
max_elems++;
a=realloc(a,max_elems);
...
}

You should also consider linked lists. From standard:



"数组类型描述了具有特定成员对象类型的连续分配的非空对象
对象,称为元素类型。

亲切的问候。


"An array type describes a contiguously allocated nonempty set of
objects with a particular member object type, called the element type".
Kind regards.


这篇关于大家好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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