Created
February 13, 2018 08:19
-
-
Save nitishk72/3230ccc93ef50edfd8ce6de089a22a92 to your computer and use it in GitHub Desktop.
Sum of two number using pointer Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
class A{ | |
int x,y,z; | |
public: | |
void add(){ | |
cout<<"Enter value of x "<<endl; | |
cin>>x; | |
cout<<"Enter value of y "<<endl; | |
cin>>y; | |
z = x + y; | |
cout<<"Sum = "<<z<<endl; | |
} | |
}; | |
int main(){ | |
A obj; | |
A *ptr; | |
ptr = &obj; | |
ptr->add(); | |
(*ptr).add(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment