SlideShare a Scribd company logo
1 of 2
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

More Related Content

Similar to How do arrays compare with variables and how do they differ- Give a si.docx

Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 

Similar to How do arrays compare with variables and how do they differ- Give a si.docx (20)

Data structure array
Data structure  arrayData structure  array
Data structure array
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Array
ArrayArray
Array
 
DSA Unit II array.pptx
DSA Unit II array.pptxDSA Unit II array.pptx
DSA Unit II array.pptx
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
 
1st lecture.ppt
1st lecture.ppt1st lecture.ppt
1st lecture.ppt
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
C++ arrays part1
C++ arrays part1C++ arrays part1
C++ arrays part1
 
Arrays in JAVA.ppt
Arrays in JAVA.pptArrays in JAVA.ppt
Arrays in JAVA.ppt
 
02 arrays
02 arrays02 arrays
02 arrays
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
OOPs with java
OOPs with javaOOPs with java
OOPs with java
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
 

More from tpaula2

How can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docxHow can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docx
tpaula2
 
Hi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docxHi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docx
tpaula2
 
1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docx1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docx
tpaula2
 
1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docx1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docx
tpaula2
 

More from tpaula2 (20)

How can I calculate the missing amounts for each of the independent ca.docx
How can I calculate the missing amounts for each of the independent ca.docxHow can I calculate the missing amounts for each of the independent ca.docx
How can I calculate the missing amounts for each of the independent ca.docx
 
How can other countries respond to international piracy-Solutiona-) St.docx
How can other countries respond to international piracy-Solutiona-) St.docxHow can other countries respond to international piracy-Solutiona-) St.docx
How can other countries respond to international piracy-Solutiona-) St.docx
 
How do I block a certain range of IP addresses in a CENTOS server from.docx
How do I block a certain range of IP addresses in a CENTOS server from.docxHow do I block a certain range of IP addresses in a CENTOS server from.docx
How do I block a certain range of IP addresses in a CENTOS server from.docx
 
How can we reduce software requirement errors -SolutionIf we want to r.docx
How can we reduce software requirement errors -SolutionIf we want to r.docxHow can we reduce software requirement errors -SolutionIf we want to r.docx
How can we reduce software requirement errors -SolutionIf we want to r.docx
 
How can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docxHow can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docx
 
How change in a corporation-'s natural and societal environments can a.docx
How change in a corporation-'s natural and societal environments can a.docxHow change in a corporation-'s natural and societal environments can a.docx
How change in a corporation-'s natural and societal environments can a.docx
 
How can you prevent intruders from accessing your wireless network- a).docx
How can you prevent intruders from accessing your wireless network- a).docxHow can you prevent intruders from accessing your wireless network- a).docx
How can you prevent intruders from accessing your wireless network- a).docx
 
How are standing waves similar to beats and how are they different- Ty.docx
How are standing waves similar to beats and how are they different- Ty.docxHow are standing waves similar to beats and how are they different- Ty.docx
How are standing waves similar to beats and how are they different- Ty.docx
 
How are corporate abuse of power corporate fraud- and corporate econom.docx
How are corporate abuse of power corporate fraud- and corporate econom.docxHow are corporate abuse of power corporate fraud- and corporate econom.docx
How are corporate abuse of power corporate fraud- and corporate econom.docx
 
How can biometric technology be used to fight cybercrime and cyber rel.docx
How can biometric technology be used to fight cybercrime and cyber rel.docxHow can biometric technology be used to fight cybercrime and cyber rel.docx
How can biometric technology be used to fight cybercrime and cyber rel.docx
 
Holmes- CPA- assisted Williams Corporation in preparing its financial.docx
Holmes- CPA- assisted Williams Corporation in preparing its financial.docxHolmes- CPA- assisted Williams Corporation in preparing its financial.docx
Holmes- CPA- assisted Williams Corporation in preparing its financial.docx
 
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docxHNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
 
Hi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docxHi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docx
 
Hi! I think the answer is C Outsource the software- I juyst wanted to.docx
Hi! I think the answer is C Outsource the software- I juyst wanted to.docxHi! I think the answer is C Outsource the software- I juyst wanted to.docx
Hi! I think the answer is C Outsource the software- I juyst wanted to.docx
 
Hi all! someone help me pls Fraud examination I need to write an essay.docx
Hi all! someone help me pls Fraud examination I need to write an essay.docxHi all! someone help me pls Fraud examination I need to write an essay.docx
Hi all! someone help me pls Fraud examination I need to write an essay.docx
 
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docxHerbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
 
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docxHere is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
 
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
 
1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docx1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docx
 
1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docx1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

How do arrays compare with variables and how do they differ- Give a si.docx

  • 1. 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;
  • 2. 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