This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef70c0f
commit 31a2fa0
Showing
11 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Struttura semplificata di un programma | ||
|
||
In prog1 vedremo solamente programmi contenuti in un unico file sorgente. | ||
|
||
## Step compilazione | ||
1. il file sorgente viene interpretato dal *pre-processore* e le direttive (iniziano con #) unwrappate | ||
2. la nuova versione estesa del programma viene memorizzata in un file temporaneo | ||
3. il file temporaneo passa per il compilatore | ||
|
||
## Dichiarazione e definizione | ||
Dichiarazione = istruzione in cui viene introdotto un nuovo *identificatore* | ||
|
||
Definizione sottoinsieme di dichiarazione: allocazione spazio moemoria | ||
|
||
## Struttura C | ||
``` | ||
<direttive al pre-processore> | ||
int main() { | ||
<dichiarazione> | ||
<dichiarazione> | ||
<dichiarazione> | ||
... | ||
<istruzione diversa da dichiarazione> | ||
<istruzione diversa da dichiarazione> | ||
<istruzione diversa da dichiarazione> | ||
} | ||
``` | ||
|
||
Vietate le dichiarazioni in mezzo al codice | ||
|
||
## Struttura Cpp | ||
``` | ||
<direttive al pre-processore> | ||
int main() { | ||
<istruzione qualsiasi> | ||
<istruzione qualsiasi> | ||
<istruzione qualsiasi> | ||
... | ||
} | ||
``` | ||
|
||
## Funzione main | ||
Funzione speciale, tre caratteristiche principali: | ||
1. deve essere sempre presente | ||
2. entry point del programma | ||
3. dopo l'ultima istruzione del main il programma termina | ||
|
||
## Problem solving | ||
1. capire il problema | ||
2. cercare idea risolutiva | ||
3. definire l'algoritmo | ||
4. testarlo su carta | ||
5. implementarlo | ||
6. testarlo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Assegnamento | ||
Espressione di assegnamento: | ||
`nomevar = espressione` | ||
|
||
Istruzione assegnamento: | ||
`<espressione assegnamento>` | ||
|
||
Tabella dei simboli: simbolo -> indirizzo | ||
|
||
Ogni assegnamento implica una scrittura della porzione di memoria in cui è contenuta la variabile. | ||
|
||
*lvalue* = left value | ||
*rvalue* = right value | ||
|
||
`lvalue = rvalue` <--> _indirizzo = espressione_ | ||
Ordine esecuzione: risoluzione espressione rvalue, assegnamento al valore del simbolo di sinistra. | ||
|
||
Anche l'espressione di assegnamento ha un risultato (un proprio valore), ovvero *l'indirizzo della variabile*. In C il risultato dell'assegnamento è il valore del rvalue. | ||
|
||
Assegnamento multiplo: `c = d = 2`. Parti da destra: `c = (d = 2)`. Funziona sia in C che in C++ | ||
|
||
TODO: link esercizio e completa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Sintassi | ||
Un programma C/C++ è una sequenza di *token* delimitate da *whitespaces*. | ||
TODO: completa | ||
Tipi token: | ||
- operatori | ||
- parole riservate | ||
... | ||
TODO: completa | ||
|
||
## Identificatori | ||
<identificatore> ::= <Lettera> {<Lettera> | <Cifra>} | ||
- <lettera> = lettere maiusc e minusc + underescore | ||
- no inizio con numero | ||
- no parole riservate | ||
|
||
## Commenti | ||
=> parte di codice non interpretata dal compilatore | ||
|
||
`// /* ... */` | ||
|
||
Best practice: | ||
``` | ||
/* | ||
* | ||
* | ||
*/ | ||
``` | ||
|
||
# Spazi bianchi | ||
Unico separatore obbligatorio tra identificatore e parola chiave. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int a, b; | ||
cout << "Inserisci valore a: "; | ||
cin >> a; | ||
cout << "Inserisci valore b: "; | ||
cin >> b; | ||
a += b; | ||
b = a-b; | ||
a -= b; | ||
cout << "Dopo lo scambio: a=" << a << ", b=" << b << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int a; | ||
cout << "Immetti numero: "; | ||
cin >> a; | ||
cout << "Risultato: " << a%10 << a%100/10 << a/100 << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int a; | ||
cout << "Immetti numero: "; | ||
cin >> a; | ||
int res = a%10 + | ||
cout << "Risultato: " << a%10 << a%100/10 << a/100 << endl; | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
const int A = 10; // Best practice: constants name should be uppercase | ||
// A = 20; // lvalue must be variable | ||
cout << "Il valore della costante è " << A << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdlib.h> | ||
|
||
int main() { | ||
int a = 10; | ||
printf("a vale: %d\n", a); | ||
int b = 20; | ||
const c = 100; | ||
printf("b vale: %d\n", b); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
using namespace std; | ||
|
||
int main() { | ||
cout << 0/abs(0); | ||
return 0; | ||
} |