How do arrays compare with variables and how do they differ- Give a si.docx
tpaula2
8 views
2 slides
Feb 03, 2023
Slide 1 of 2
1
2
About This Presentation
How do arrays compare with variables and how do they differ? Give a simple example
(Programming Logic and Design)
Solution
Arrays : Array is a homogeneous (same kind of elements) collection of elements in memory in a contagious locations.
The first element of array is stored at index =0 and last ele...
How do arrays compare with variables and how do they differ? Give a simple example
(Programming Logic and Design)
Solution
Arrays : Array is a homogeneous (same kind of elements) collection of elements in memory in a contagious locations.
The first element of array is stored at index =0 and last element is stored at index=size-1.
For example, int marks [5] ={10,20,30,40,50};
10
20
30
40
50
Variable : The variable is a name given to memory location in a computer memory. The element is stored in that memory location can be pointed by the variable name.
For example, int id=10;
Where id is a name given to the memory location where the value 10 is stored.
Comparison of array elements with variables :
Since arrays are stored index based, the elements are compared using index location of the element in an array.
int min=50;
for(int i=0;i<5;i++)
//comparison of array element with variable, min
if(marks[index]==min)
//code follows
.
Size: 17.15 KB
Language: en
Added: Feb 03, 2023
Slides: 2 pages
Slide Content
How do arrays compare with variables and how do they differ? Give a simple example
(Programming Logic and Design)
Solution
Arrays : Array is a homogeneous (same kind of elements) collection of elements in memory in a
contagious locations.
The first element of array is stored at index =0 and last element is stored at index=size-1.
For example, int marks [5] ={10,20,30,40,50};
10
20
30
40
50
Variable : The variable is a name given to memory location in a computer memory. The element
is stored in that memory location can be pointed by the variable name.
For example, int id=10;
Where id is a name given to the memory location where the value 10 is stored.
Comparison of array elements with variables :
Since arrays are stored index based, the elements are compared using index location of the
element in an array.
int min=50;
for(int i=0;i<5;i++)
//comparison of array element with variable, min
if(marks[index]==min)
//code follows
10 20 30 40 50