Pointers And Operators

  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Pointers And Operators as PDF for free.

More details

  • Words: 147
  • Pages: 1
Computer Science (083)

Pointers to Classes

Pointers to classes (Example) #include #include class A // ********** BASE CLASS ************ { int x2,x3; public : int x1; void initialize(int a,int b,int c) {x1=a;x2=b;x3=c; cout <<"Data members initialized ....\n"; getch(); } void display() {cout<<x1<<'\t'<<x2<<'\t'<<x3<<endl;} }; void main() { clrscr(); A obj; obj.initialize(10,20,30); A * ptr=&obj; ptr->display(); cout<<"\nptr->x1 = "<x1; cout<<"\n(*ptr).x1 = "<<(*ptr).x1 ; // NOTE x1 is declared under public section //otherwise will not be accessible getch(); (*ptr).display(); getch(); }

Summary of pointer and operators (*, &, ., ->) expression can be read as *x pointed by x &x address of x x.y member y of object x x->y member y of object pointed by x (*x).y member y of object pointed by x (equivalent to the previous one)

NOTE : What has been discussed for classes is also valid for pointers to structures. By Nita Arora

Related Documents

Pointers And Operators
April 2020 3
Pointers
November 2019 36
Pointers
May 2020 9
Pointers
November 2019 22
Pointers
November 2019 27
Pointers
November 2019 18