How can you quickly find the number of elements stored in a
a) static array or in b) dynamic array ?
How can you quickly find the number of elements stored in a
a) static array or in b) dynamic array ?
dynamic array
static array
-----------
static array access would be more faster. Since its the index move.
And the static array space is allocated at stack.
ex: a[4]={'1','2','3','4'}
for(i=0;i<4;i++)
{
printf("%d",a[i]);
}
Since its the index jump this would be faster.
Dynamic array
--------------
Dynamic array would be slow since its pointer(address) increment.
static array
dynamic array:
- if array has bulk elements then its efficient.
dynamic array is quick to find elements
Is this a trick question
First of all, you need to specify the language where you want this answer.
2.
Lets assume you are programming in C. Then, there is no way one can find the number of elements stored in a static array. If there is way, I would like to know how it is done.
3.
One might only find the maximum no of elements in an array if there is a special value entered programatically that indicates that we have reached the end of the array.
I dont know man dont disturb