La versione più recente è stata modificata il 2006-03-13 14:38:16 da SoNiC
Aggiunzioni:
Torna a Laboratorio di Sistemi Operativi
Modificato il 2006-03-13 13:43:50 da SoNiC
Omissioni:
><tr><td>Tipo</td><td>Rappresentazione</td><td>Dimensione</td></tr><tr><td>char</td><td>yes</td><td>no</td></tr> <tr><td>no</td><td>no</td><td><br /></td></tr></table>""
Modificato il 2006-03-13 13:43:28 da SoNiC
Aggiunzioni:
><tr><td>Tipo</td><td>Rappresentazione</td><td>Dimensione</td></tr><tr><td>char</td><td>yes</td><td>no</td></tr> <tr><td>no</td><td>no</td><td><br /></td></tr></table>""
Omissioni:
>
<tr>
<td>Tipo</td>
<td>Rappresentazione</td>
<td>Dimensione</td>
</tr>
<tr>
<td>char</td>
<td>yes</td>
<td>no</td>
</tr>
<tr>
<td>no</td>
<td>no</td>
<td><br /></td>
</tr>
</table>""
Modificato il 2006-03-13 13:42:40 da SoNiC
Aggiunzioni:
>
<tr>
<td>Tipo</td>
<td>Rappresentazione</td>
<td>Dimensione</td>
</tr>
<tr>
<td>char</td>
<td>yes</td>
<td>no</td>
</tr>
<tr>
<td>no</td>
<td>no</td>
<td><br /></td>
</tr>
</table>""
Modificato il 2006-03-13 13:40:14 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Modificato il 2006-03-13 13:39:56 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Modificato il 2006-03-13 13:39:34 da SoNiC
Aggiunzioni:
Modificato il 2006-03-13 13:38:34 da SoNiC
Aggiunzioni:
printf("Stampa il contenuto di a: %c\ne quello di b: %c\n",a,b);
Omissioni:
printf("Stampa il contenuto di a: %c\n e quello di b: %c\n",a,b);
Modificato il 2006-03-13 13:37:54 da SoNiC
Aggiunzioni:
printf("Stampa il contenuto di a: %c\n e quello di b: %c\n",a,b);
Omissioni:
printf("Stampa il contenuto di a: %c e quello di b%c\n",a,b);
Modificato il 2006-03-13 13:37:13 da SoNiC
Aggiunzioni:
char a='C',b='D';
printf("Stampa il contenuto di a: %c e quello di b%c\n",a,b);
Omissioni:
char a='C';
Modificato il 2006-03-13 13:35:44 da SoNiC
Aggiunzioni:
niente paura, anche per la dichiarazione di più variabili il costrutto rimane tale, le variabili restano sempre separate da una virgola, ad esempio:
char a='C', b='D';
vediamo un esempio pratico modificando il nostro programmino:
Omissioni:
possiamo quindi modificare il nostro programmino così:
Modificato il 2006-03-13 13:32:40 da SoNiC
Aggiunzioni:
char a='C';
Modificato il 2006-03-13 13:32:11 da SoNiC
Aggiunzioni:
Come possiamo vedere, la dichiarazione viene effettuata in questo modo:
<tipo> <nome>;
Possiamo dichiarare più variabili separandole con il carattere "," (virgola) ad es.:
char a, b;
L'istruzione successiva invece assegna il carattere C alla variabile a.
Possiamo anche racchiudere l'istruzione di dichiarazione direttamente alla dichiarazione così:
<tipo> <nome>=<valore>;
possiamo quindi modificare il nostro programmino così:
Modificato il 2006-03-13 13:24:42 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Modificato il 2006-03-13 13:24:33 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Modificato il 2006-03-13 13:24:19 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Modificato il 2006-03-13 13:23:29 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Modificato il 2006-03-13 13:22:49 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Modificato il 2006-03-13 13:22:31 da SoNiC
Aggiunzioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Omissioni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
La versione più vecchia di questa pagina è stata modificata il 2006-03-13 13:22:06 da SoNiC []
Vista della pagina:
Dichiarazione di variabili
Come visto nel corso di programmazione, le variabili allocano uno spazio nella memoria del programma, bisogna quindi specificarne nome e tipo.
Ad ogni tipo corrisponde un modo diverso di allocare la memoria in base al quale il valore contenuto dalla variabile può variare, in parole povere è semplicemente lo spazio preparato per l'allocazione, vediamone alcuni:
| Tipo |
Rappresentazione |
Dimensione |
| char |
da -128 a 127 |
1 Byte (8 bit) |
| unsigned char |
da 0 a 255 |
1 Byte (8 bit) |
| int |
|
variabile 2-4 Byte |
| unsigned int |
|
variabile 2-4 Byte |
| short int |
da -2^15 - 1 a 2^15 |
2 Byte (16 bit) |
| unsigned short |
da 0 a 2^16 - 1 |
2 Byte (16 bit) |
| long |
da -2^31 - 1 a 2^31 |
4 Byte (32 bit) |
| unsigned long |
da 0 a 2^32 - 1 |
4 Byte (32 bit) |
| float |
|
4 Byte (32 bit) |
| double |
|
8 Byte (64 bit) |
Torniamo al nostro "Ciao mondo" e modifichiamolo inserendo una variabile di tipo char:
#include <stdio.h>
main
()
{
char a;
a=
'C';
printf("Stampa il contenuto della variabile a: %c\n",a
);
}