

Gli array in C++
Presentation
•
Computers
•
9th - 12th Grade
•
Practice Problem
•
Hard
Lucia Intelisano
FREE Resource
9 Slides • 0 Questions
1
Gli array in C++
2
Definizione
Un array è una sequenza di elementi dello stesso tipo, immagazzinata in locazioni di memoria contigue. Ad un array è associato un identificativo che può essere indicizzato numericamente per accedere ai singoli elementi. La prima locazione dell'array è associata all'indice 0, e coincide con l'indirizzo dell'indentificativo stesso.
3
Dichiarazione
Un array è una variabile, ed in quanto tale valgono le stesse regole per la dichiarazione e la definizione dei suoi valori
// dichiarazione senza inizializzazione, con dimensione pari a 5
int myArray[5];
// dichiarazione e definizione, la dimensione è desunta dal compilatore
int myArray[] = {2, 4, 6, 8, 10};
4
Rappresentazione di un array in memoria
5
Uso degli array
Ogni elemento ha una dimensione in byte pari a quella del tipo nominale dell'array, in questo caso int, e l'indice ad esso associato è un numero progressivo che identifica la sua posizione assoluta.
L'operatore parentesi quadre [] viene usato anche per accedere agli elementi di un array in base al loro indice come mostrato di seguito per alterare o leggere il valore contenuto:
6
Uso degli array
int myArray[] ={2, 4, 6, 8, 10};
// scrittura
myArray[3] = 123; // {2, 4, 6, 123, 10};
// lettura
int a = myArray[2]; // a = 6;
7
Scansione di un array
Un array può essere facilmente scandito mediante uno dei costrutti iterativi del linguaggio, ad esempio il ciclo for, come mostrato nel listato seguente:
#include <iostream>
int main() {
int myArray[] = {2, 4, 6, 8, 10};
for (int i=0; i<5; i++) {
cout << "index: " << i << " - value: " << myArray[i] << "\n";
}
return 0;
}
8
Scansione di un array
Che produce il seguente output:
index: 0 - value: 2
index: 1 - value: 4
index: 2 - value: 6
index: 3 - value: 8
index: 4 - value: 10
9
Scansione di un array
Che produce il seguente output:
index: 0 - value: 2
index: 1 - value: 4
index: 2 - value: 6
index: 3 - value: 8
index: 4 - value: 10
Gli array in C++
Show answer
Auto Play
Slide 1 / 9
SLIDE
Similar Resources on Wayground
9 questions
Unit 1: Lesson 3 Circles & Square
Presentation
•
9th - 12th Grade
7 questions
Lesson 1
Presentation
•
10th - 12th Grade
7 questions
Lesson 2
Presentation
•
10th - 12th Grade
10 questions
Easter eggs e Doodles
Presentation
•
9th - 12th Grade
6 questions
parole gentili significato e colori
Presentation
•
KG
8 questions
Function Notation
Presentation
•
9th - 12th Grade
8 questions
Exploring Forest Biomes
Presentation
•
9th - 12th Grade
8 questions
7.4 Arc Length
Presentation
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
GPA Lesson
Presentation
•
9th - 12th Grade
7 questions
Albert Einstein
Quiz
•
3rd Grade
31 questions
Bridge A Review
Quiz
•
3rd Grade
6 questions
Blue Sue and Red Ruth
Quiz
•
3rd Grade
8 questions
(Day12 HW) Inverse Trig Ratios
Quiz
•
9th Grade
20 questions
Summer Geometry QUIZ (Week3)
Quiz
•
9th Grade
16 questions
Theme Practice
Quiz
•
7th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
Discover more resources for Computers
10 questions
GPA Lesson
Presentation
•
9th - 12th Grade
8 questions
(Day12 HW) Inverse Trig Ratios
Quiz
•
9th Grade
20 questions
Summer Geometry QUIZ (Week3)
Quiz
•
9th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
16 questions
Warm Up: Basics of Geometry
Quiz
•
9th Grade
16 questions
Translations and Reflections
Quiz
•
9th - 10th Grade
17 questions
High School Survival Guide
Presentation
•
9th - 12th Grade
20 questions
Banking
Quiz
•
9th - 12th Grade