1,886 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

6 6 votes
2 2 answers
370
370 views
GO Classes asked Jun 29
370 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
247
247 views
GO Classes asked Jun 23
247 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
317
317 views
GO Classes asked Jun 23
317 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
352
352 views
GO Classes asked Jun 22
352 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}$ $\...