-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcasting.cpp
More file actions
34 lines (24 loc) · 721 Bytes
/
casting.cpp
File metadata and controls
34 lines (24 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
int main() {
// ------------------------------
// Esempio di Casting Implicito
// ------------------------------
int i = 10;
float result_float = i;
float f = 3.14;
double result_double = f;
printf("Casting implicito:\n");
printf("Int a Float: %d -> %f\n", i, result_float);
printf("Float a Double: %f -> %f\n", f, result_double);
// ------------------------------
// Esempio di Casting Esplicito
// ------------------------------
int a = 10;
int b = 3;
float c;
c = a/b;
printf("c (con perdita di informazione) %f\n", c);
c = (float)a/b;
printf("c (senza perdita di informazione) %f\n", c);
return 0;
}