473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Difference between a static array and a dynamic array

can anyone explain what is main difference between the static array and a dynamic array....also i am confused with dynamic array and dynamic allocated array????can anyone help me...
Mar 15 '14 #1

✓ answered by weaknessforcats

A static array has memory allocated at compile time.

Please note: This has nothing to do with the C/C++ static storage class specifier.

A dynamic array has memory allocated at run time.

A dynamic array and a dynamically allocated array are the same thing.

4 30383
weaknessforcats
9,208 Expert Mod 8TB
A static array has memory allocated at compile time.

Please note: This has nothing to do with the C/C++ static storage class specifier.

A dynamic array has memory allocated at run time.

A dynamic array and a dynamically allocated array are the same thing.
Mar 15 '14 #2
what is the difference between compile time and runtime???
Mar 15 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
Compile time is when your code is converted by the compiler into machine instructions. The memory for the static array will be allocated when these machine instructions execute. There is no way to change the amount of memory allocated when the program is running.

Run time is when the program is actually running. An array created at this time requires the number of bytes required to be submitted to a memory allocation function which will allocate the memory and return the address of the allocation:

Expand|Select|Wrap|Line Numbers
  1. int arr[25];   //static array. Can't change the 25 later.
  2. int* ptr;
  3. int num = 25;
  4.  
  5.      ptr = (int*)malloc(num * sizeof(int)); //dynamic array
  6.  
  7.     //num can be changed later for a different sized array.
You might read this: http://bytes.com/topic/c/insights/77...rrays-revealed
Mar 16 '14 #4
Sherin
77 64KB
An array created at compile time by specifying size in the source code has a fixed size and cannot be modified at run time. The process of allocating memory at compile time is known as static memory allocation and the arrays that receives static memory allocation are called static arrays.

This approach works fine as long as we know exactly what our data requirements are. Suppose we don't know what are our data requirements in that case we can use dynamic arrays.

A static array is declared at compile time; thus, its size must be a compile time constant. Most older languages, such as FORTRAN, COBOL and even Pascal, use this technique exclusively. These cannot have variable sizes because allocation of the array is done at compile-time. These are usually placed on the stack. The memory management is easy because everything is done at compile-time and no re-sizing is allowed.

A dynamic array may be declared at compile-time but it is not dimensioned (the number of elements determined) until run-time. Thus, the value that determines the size may come from a constant or variable.
Aug 26 '20 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
2
by: raxitsheth | last post by:
I am using array in my progrm... is there any tool /tips so that i can convert my program to Dynamic Array...so that I can Add more Element to Array.... Code is around 4000 line 'C' (not C++)...
1
by: lemonade | last post by:
Hello! Can someone explain to me the difference between dynamic array of pointers vs dynamic array of objects by giving a real life example. Following is the code that I am using for dynamic...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
5
by: markww | last post by:
Hi, Can someone explain to me what static and dynamic dispatch are and what the difference is between the two? Do this even occurr in C++? Thanks
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
19
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.28 * STATEMENT * write a programme to read the standard input and build a vector of integers from values that are read....
1
by: Gurur | last post by:
Hi all, I have a doubt. If I have 2 structures and one is parent of other , ie the child structure is present in the parent one . And if the child structure is declared as dynamic array in the...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
1
by: lumumba401 | last post by:
Hello everybody, i am asking about how to define a bidimensional dynamic array as a global variable to use as incoming variable in a function Let us see , for example in a part of a programm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.