

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
7 questions
12/18-Dorchester2-Test Day
Presentation
•
9th - 12th Grade
7 questions
Agenda 2030 - Introduzione
Presentation
•
9th - 12th Grade
7 questions
Marx and Smith
Presentation
•
9th - 12th Grade
6 questions
Sprite Properties
Presentation
•
9th - 12th Grade
10 questions
CMU CS Regular Poygons and Stars
Presentation
•
9th - 12th Grade
10 questions
C++ Operators
Presentation
•
9th - 12th Grade
2 questions
Bell Ringer
Presentation
•
9th - 12th Grade
7 questions
Rima LIII
Presentation
•
9th - 12th Grade
Popular Resources on Wayground
16 questions
Grade 3 Simulation Assessment 2
Quiz
•
3rd Grade
19 questions
HCS Grade 5 Simulation Assessment_1 2526sy
Quiz
•
5th Grade
10 questions
Cinco de Mayo Trivia Questions
Interactive video
•
3rd - 5th Grade
17 questions
HCS Grade 4 Simulation Assessment_2 2526sy
Quiz
•
4th Grade
24 questions
HCS Grade 5 Simulation Assessment_2 2526sy
Quiz
•
5th Grade
13 questions
Cinco de mayo
Interactive video
•
6th - 8th Grade
20 questions
Math Review
Quiz
•
3rd Grade
30 questions
GVMS House Trivia 2026
Quiz
•
6th - 8th Grade