Solved

Dynamic Arrays

Posted on 1999-01-17
5
195 Views
Last Modified: 2010-05-18
Is there anyway in C or C++ to use initialise the size of an array at run time and also be able to change it? Thanks.
0
Comment
Question by:onka34
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1258160
malloc/realloc
0
 

Expert Comment

by:jji
ID: 1258161
Don't forget 'free' & 'calloc'.
0
 
LVL 1

Accepted Solution

by:
arunprakash earned 100 total points
ID: 1258162
try using the Standard template library.
it has classes called Deque, vector which can take care of this dynamic expanding and shrinking arrays

u can do
array.push_back(element)
element can be off any type
0
 

Expert Comment

by:bsutris
ID: 1258163
c cannot change array size but if you use pointer and you use it like an array, you can change the size of the pointer
0
 

Author Comment

by:onka34
ID: 1258164
Thanks :-)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question