Basic Pointer Manipulations Example: Display 10.2 Basic Pointer Manipulations(2 of 2) 1 pl new int; 1 *p1=88; 8 cout <<"*p1 =="<*p1 <endl; 19 cout <<"*p2 =="<<*p2 <endl; 20 cout <"Hope you got the point of this example!\n"; 2 return 0; 22 SAMPLE DIALOGUE *p1=42 *p2==42 *p1=53 *p2=53 *p1==88 *p2==53 Hope you got the point of this example! Copyright 2006 Pearson Addison-Wesley.All rights reserved. 10-16
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 10-16 Basic Pointer Manipulations Example: Display 10.2 Basic Pointer Manipulations (2 of 2)
Basic Pointer Display o.3 Explanation of Displayo. Manipulations (a int *pl,*p2; Graphic: ▣ (e) *p2=53: Display 10.3 Explanation of Display 10.2 p1 ( p1=88: 01 (d) p2=p1; Copyright006 Pearson Addison-Wesley.All rights reserved. 10-17
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 10-17 Basic Pointer Manipulations Graphic: Display 10.3 Explanation of Display 10.2
More on new Operator Creates new dynamic variable Returns pointer to the new variable ◆If type is class type: Constructor is called for new object Can invoke different constructor with initializer arguments: MyClass *mcPtr; mcPtr new MyClass(32.0,17); Can still initialize non-class types: int *n; n new int(17);//Initializes *n to 17 Copyright006 Pearson Addison-Wesley.All rights reserved. 10-18
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 10-18 More on new Operator ¨ Creates new dynamic variable ¨ Returns pointer to the new variable ¨ If type is class type: ¨ Constructor is called for new object ¨ Can invoke different constructor with initializer arguments: MyClass *mcPtr; mcPtr = new MyClass(32.0, 17); ¨ Can still initialize non-class types: int *n; n = new int(17); //Initializes *n to 17