/* * Programmieren fuer Physiker, SS 2010 * * Pointers, Bsp. 1 */ #include using namespace std ; int main() { double x ; double* p ; // p ist eine Variable, die auf ein double zeigen kann cout << "p:" << p << endl ; // der Pointer ist uninitialisiert... p = &x ; // p zeigt nun auf x (p := Adresse von x) x = 3.14 ; cout << "p:" << p << endl ; cout << "&x:" << &x << endl ; cout << "Inhalt von p: " << *p << endl ; (*p) = 25 ; cout << "p:" << p << endl ; cout << "Inhalt von p: " << *p << endl ; cout << "x: " << x << endl ; // folgendes geht nicht: int a ; // p = &a ; // weil p eine Zeigervariable auf ein double ist! }