html5-img
1 / 11

計算機概論實習 2007-06-15

計算機概論實習 2007-06-15. Claim a Parameter. int a; a = 5;. 5. 'A'. char c; c = 'A';. Print a Parameter. cout << a; cout << &a;. 5. 'A'. Claim a Pointer. int* ap; ap = &a;. 5. 0x0001. Print a Point. cout << ap; cout << ≈ cout << *ap;. 5. 0x0001. Claim a Class (Object).

werner
Download Presentation

計算機概論實習 2007-06-15

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 計算機概論實習2007-06-15

  2. Claim a Parameter int a; a = 5; 5 'A' char c; c = 'A';

  3. Print a Parameter cout << a; cout << &a; 5 'A'

  4. Claim a Pointer int* ap; ap = &a; 5 0x0001

  5. Print a Point cout << ap; cout << &ap; cout << *ap; 5 0x0001

  6. Claim a Class (Object) class A{ int p; int f(){return p;} }; A a; a.a = 5; 5 A &ap = a;

  7. Print the Content of Object 5 4 cout << "&a: " << &a << endl; cout << "&ap: " << &ap << endl; cout << "a.f(): " << a.f() << endl; cout << "ap.f(): " << ap.f() << endl; a.a = 4; cout << "a.f(): " << a.f() << endl; cout << "ap.f(): " << ap.f() << endl; &a: 0x0001 &ap: 0x0001 a.f(): 5 ap.f(): 5 a.f(): 4 ap.f(): 4

  8. Call by Value void main(){ int a; a = 5; f(a); } void f(int c){ c = 4; } 1 2 5 3 2 3 4 4 5 3 4 1 2 4 3

  9. Call by Address void main(){ int a = 5; f(a); } void f(int* ap){ *ap = 4; ap = ap + 1; } 1 2 4 5 2 1 3 3 4 1 2 3 4 2 4 0x0001 0x0005

  10. Call by Reference void main(){ A a; a.a = 5; f(a); } void f(A& ao){ ao.a = 4; } 1 2 4 5 1 3 2 4 3 4 1 2 3 4

  11. Try it!!! • Please explain that what happen in the following code. • Please write a sample code to prove your mind. A a1,a2; a1.a = 5; a2 = a1; : :

More Related