top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

C++: What is the difference between an ARRAY and a LIST?

+1 vote
62 views
C++: What is the difference between an ARRAY and a LIST?
posted Nov 11, 2013 by Ganesh Kumar

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

0 votes

Array: For Array memory allocated is static and continuous.
List: For List memory allocated is dynamic and Random.

Array: User need not have to keep in track of next memory allocation.
List: User has to keep in Track of next location where memory is allocated.

Array: Size of the Array is fixed:
List: Size is not fixed, virtually infinite.

answer Nov 11, 2013 by Salil Agrawal
In case of array we can allocate memory dynamically too and do it realloc.
But if required continuous memory is not available then realloc will fail while we have memory.
So if we do not know the size of data better to use Link List.
0 votes

Array uses direct access of stored members, list uses sequencial access for members.

//With Array you have direct access to memory position 5
Object x = a[5]; // x takes directly a reference to 5th element of array

//With the list you have to cross all previous nodes in order to get the 5th node:
list mylist;
list::iterator it;

for( it = list.begin() ; it != list.end() ; it++ )
{
if( i==5)
{
x = *it;
break;
}
i++;
}

answer Nov 20, 2014 by Manikandan J
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...