C++ Program For Implementation of Pointers

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Program for Pointer demo
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int main()
{

    /*     Pointer Part 1 */
        //int a=50,*p,**r;
        //clrscr();
        // p=&a;
        // r=&p;
        // cout<<" \nValue of a: "<<a;
        // cout<<" \nAddress of a: "<<&a;
        // cout<<" \n value of p: "<<p;
        // cout<<"\n value of *p: "<<*p;
        // cout<<"\nAddress of p :"<<&p;
        // cout<<"\n value of r is: "<<r;
        // cout<<"\n value of *r is: "<<*r;
        // cout<<"\n value of **r is: "<<**r;
        // ++**r;
        // cout<<" \nValue of a: "<<a;

        //  p=&a;
        //  cout<<" Value  of a is before pointer: "<<a;
        //  ++*p;
        //  cout<<" \nValue  of a is after pointer: "<<a;

/*     Pointer Part 1.1 */
    //   int a=5,*p1,*p2;
    //   p1=&a;
    //   p2=&a;
    //   ++*p1;   //6
    //   ++*p2;   //7
    //   --a;   //6
    //   cout<<"\n value of a: "<<a;
    //   cout<<"\n value of *p1: "<<*p1;
    //   cout<<"\n value of *p2: "<<*p2;

/*     Pointer Part 1.2 */
          //int a=15,b=10,*p1,*p2;
     
    //         p1=&a;
    //         p2=&b;
    //         ++*p1;
    //         ++*p2;
    //         a=a-3;
    //         b=b+5;
    //         p1=&b;
    //         ++*p1;
    //         ++*p2;
    //         a=a+5;
    //         b=b-2;
    //         p2=&a;
    //    cout<<"\n value of a: "<<a;
    //     cout<<"\n value of b: "<<b;
    //    cout<<"\n value of *p1: "<<*p1;
    //    cout<<"\n value of *p2: "<<*p2;

   return(0);
}

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *