1,865 views

2 Answers

Best answer
8 8 votes

Answer and Explanation 

According to the concept of Spatial Locality, if the data in location 'n' is accessed, there is a high chance that the data in location 'n+1' will be accessed soon. Therefore, several contiguous memory blocks are loaded onto the machine's cache to speed up the data access. Since arrays are stored in a contiguous manner, they are best suited for this and thereby improving performance.

• selected by
1 1 vote

All the elements of array are placed in consecutive memory location, unlike linked list, whose every element is placed at random location.

While accessing memory, memory management system always fetch block of words in cache from memory, so in one block fetch, CPU can get many array elements in one block.

locality of reference: is a term for the phenomenon in which the same values, or related storage locations, are frequently accessed

Position:
Show:

Related questions

5 5 votes
2 2 answers
328
328 views
GO Classes asked Jun 29
328 views
What is the output of the following code?#include <stdio.h struct Student { int roll; int marks; }; int main() { struct Student s[3] = { {1, 70}, {2, 80}, {3, 90} }; s .m...
6 6 votes
1 1 answer
209
209 views
GO Classes asked Jun 23
209 views
What will happen when the following code is compiled?#include <stdio.h int main() { int a[] = {10, 20, 30}; a = a + 1; printf("%d", *a); return 0; }$\texttt{10}$ $\texttt...
7 7 votes
2 2 answers
268
268 views
GO Classes asked Jun 23
268 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {5, 10, 15, 20}; int *p = a + 1; printf("%d %d %td", *(p + 1), p , (p + 2) - a); return ...
7 7 votes
2 2 answers
314
314 views
GO Classes asked Jun 22
314 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {2, 4, 6, 8, 10}; printf("%d %d %d", *a, *(a + 3), 3[a]); return 0; }$\texttt{2 6 8}$ $\...