// Constants and variables #include <iostream.h> main() { const int N = 5; // The only initialization of constant int i, j = 5; // First initialization of variable cout << "Hello World\n"; i = j + N; cout << endl << i << " " << j << " " << N << endl; } |
Unterschied:
#define N 5
Es wird kein Speicherplatz für N benötigt, da N im gesamten Quelltext durch 5 ersetzt wird. |
const int N = 5;
Variable N wird gespeichert, das Programm arbeitet mit ihr. |