cpp2html 0.1-alpha © 2002 Andrea Leofreddi. To get the source click here

// 4.1: Cast implicito
#include <iostream>

using namespace std;

int main() {
	// cast espliciti
	int a(7);
	int b(3);

	float d = a / b;

	cout << "d e' " << d << endl;
	// d e' 2! perche' l'operazione a / b e' stata eseguita su
	// interi. Se volessimo maggiore precisione, dovremmo 
	// convertire (casting) a e b in float. 

	d = (float)a / (float)b; // cast C-style
	cout << "d e' " << d << endl;
	d = float(a) / float(b); // cast C++-style
	cout << "d e' " << d << endl;
}