Posts

Showing posts with the label Array

LinkedList vs Array

Both type of data structure are used to store linear data of similar types. Though, both have some positive and negative sides. Advantages of linked list over array: 1. Dynamic Size                          As the size of array is fixed, we need to know the upper limit of number of elements in advance. But in practical use, number of elements are less than the upper limit so there is wastage of allocated memory. 2. Ease of Insertion / Deletion                                          In case of array it is difficult to insert or delete any element in middle of the array as for both insertion and deletion in array, we have to shift other elements to the right or left in the array Advantages of Array over Linked List: 1. Random access is allowed in array but random access is not allowed in Linked List. We hav...

Difference between Array and Pointers

One and only difference between an array and a pointer pointing to the beginning of the array is that the compiler keeps some extra information for the arrays, to keep track of their storage information. Lets understand it more with the example by using the sizeof operator :  If we get the size of both an array and a pointer using the sizeof  operator, sizeof(ptr) will give us how much space does the pointer itself occupies (4 in case of int) while sizeof array will give us, the amount of space occupied by the whole array (if array contains 10 elements of int data-type (2 bytes) , then this operator will give 20). In general, *(array+n) is equivalent to array[n].