Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Friday

C++ TUTORIAL 19: POINTER

#include<iostream>
using namespace std;

class pointer
{
        int a , *ptr; // declaration of pointer variable
   public:
       void get();
        void multiplication();
};
void pointer :: get()
{
    cout<<"Enter a no :";
    cin>>a;
    cout<<"a :"<<a<<endl;
    ptr = &a; // address of "a" is stored at "ptr"

}
void pointer :: multiplication()
{
    *ptr = *ptr * 5;
     cout<<"After multiplication, a : "<<a<<endl;
}

int main()
{
    pointer p;
    p.get();
    p.multiplication();
    return 0;
}

OUTPUT:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...