SlideShare una empresa de Scribd logo
1 de 18
FUNDAMENTALS OF
PROGRAMMING
Lec 10
Today‟s agenda


Arrays
What are Arrays?




An array is a series of elements of the same
data type placed in contiguous memory
locations that can be individually referenced by
adding an index to a unique identifier.
That means that, for example, we can store 5
values of type int in an array without having to
declare 5 different variables, each one with a
different identifier. Instead of that, using an
array we can store 5 different values of the
same type, int for example, with a unique
identifier.
Types



One dimensional
Multi dimensional
Declaration



DataType ArrayName[size]
E.g
int Age[12]; declares a group or array of 12
values, each one being an integer
Declaration & Initialization


int billy [5]; //declaration



int billy [5] = { 16, 2, 77, 40, 12071 };



OR int billy [] = { 16, 2, 77, 40, 12071 };
Cont..
int age[4];
age[0]=23;
age[1]=34;
age[2]=65;
age[3]=74;
Important


The most important thing to remember about
array allocation is that the elements of the
array are indexed starting at 0, not 1. If the
number of cells in an array is N, then the
indexes run from 0 to N-1.
Accessing the elements of an
array.


We can access the value of any of its
elements individually as if it was a normal
variable, thus being able to both read and
modify its value.



billy[2] = 75;
a = billy[2];
b = billy [a+2];
A= billy[2] + 5;




int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;
for ( n=0 ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
sizeof







Imagine you declare an array as follows:
int number[] = {18, 42, 25, 12, 34, 15, 63, 72,
92, 26, 26, 12, 127, 4762, 823, 236, 84, 5};
Instead of counting the number of members of
this array you can use sizeof as follows:
int var= sizeof(number)/sizeof(int);
Things you cannot do




int array[10];
cout << array << endl;
int array[10];
cin >> array;
Example
int abc[5],i;
for(i=0;i<5;i++)
cin>>abc[i];
for(i=4;i>=0;i--)
cout<<abc[i];
Class Practice


Input data in two arrays and add them and
store the result in a third array.
Recall





char str[5];
Null character 0
char str[10]=“Pakistan”;
OR char str[10]={„P‟,‟A‟,‟K‟,‟I‟…..}
char str[10]=“pakistan”;
cout<<str;
Example
Copy one string into another
char str1[15],str2[15];
int I;
cout<<“ENTER STRING”;
cin>>str1;
for(i=0;str[i]!=„0‟;i++)
str2[i]=str1[i];
str2[i]=„0‟;

Next class





Think over the logic of
Insert an element into an array
Delete an element from the array
Merge two arrays

Más contenido relacionado

La actualidad más candente

Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
sotlsoc
 
Week06
Week06Week06
Week06
hccit
 
Aae oop xp_05
Aae oop xp_05Aae oop xp_05
Aae oop xp_05
Niit Care
 
1 arithmetic
1 arithmetic1 arithmetic
1 arithmetic
fyjordan9
 

La actualidad más candente (20)

Input output
Input outputInput output
Input output
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Datatypes
DatatypesDatatypes
Datatypes
 
Input output
Input outputInput output
Input output
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#
 
Array
ArrayArray
Array
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in java
 
array
array array
array
 
7array in c#
7array in c#7array in c#
7array in c#
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
Week06
Week06Week06
Week06
 
Arraysincv109102017 180831194256
Arraysincv109102017 180831194256Arraysincv109102017 180831194256
Arraysincv109102017 180831194256
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
Savitch Ch 07
Savitch Ch 07Savitch Ch 07
Savitch Ch 07
 
Savitch Ch 07
Savitch Ch 07Savitch Ch 07
Savitch Ch 07
 
Aae oop xp_05
Aae oop xp_05Aae oop xp_05
Aae oop xp_05
 
Arrays in c++
Arrays in c++Arrays in c++
Arrays in c++
 
1 arithmetic
1 arithmetic1 arithmetic
1 arithmetic
 

Destacado

Destacado (6)

10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similar a arrays

Copyright © 2012 Pearson Addison-Wesley. All rights reserve.docx
Copyright © 2012 Pearson Addison-Wesley.  All rights reserve.docxCopyright © 2012 Pearson Addison-Wesley.  All rights reserve.docx
Copyright © 2012 Pearson Addison-Wesley. All rights reserve.docx
vanesaburnand
 

Similar a arrays (20)

Savitch ch 07
Savitch ch 07Savitch ch 07
Savitch ch 07
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Copyright © 2012 Pearson Addison-Wesley. All rights reserve.docx
Copyright © 2012 Pearson Addison-Wesley.  All rights reserve.docxCopyright © 2012 Pearson Addison-Wesley.  All rights reserve.docx
Copyright © 2012 Pearson Addison-Wesley. All rights reserve.docx
 
Array in C full basic explanation
Array in C full basic explanationArray in C full basic explanation
Array in C full basic explanation
 
Array-part1
Array-part1Array-part1
Array-part1
 
Arrays
ArraysArrays
Arrays
 
pptt.pptx
pptt.pptxpptt.pptx
pptt.pptx
 
Lecture_01.2.pptx
Lecture_01.2.pptxLecture_01.2.pptx
Lecture_01.2.pptx
 
Arrays in CPP
Arrays in CPPArrays in CPP
Arrays in CPP
 
Array
ArrayArray
Array
 
Chapter 10.ppt
Chapter 10.pptChapter 10.ppt
Chapter 10.ppt
 
Lecture 6 - Arrays
Lecture 6 - ArraysLecture 6 - Arrays
Lecture 6 - Arrays
 
2 arrays
2   arrays2   arrays
2 arrays
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
Arrays_in_c++.pptx
Arrays_in_c++.pptxArrays_in_c++.pptx
Arrays_in_c++.pptx
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Array
ArrayArray
Array
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 

Último

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

arrays