20120113

How to use pointer arithmatic in C++

Program in c to learn pointer in C, pointerarithmatic2.cpp

#include<iostream>
using namespace std;
int main()
{
int num[]={10,20,30,40,50};
int *ptr1;
ptr1=&num[0];//assigning the base address of array of integer
//ptr=num;
cout<<"Value of ptr is:"<<*ptr1<<"\n";
ptr1++;
cout<<"value of ptr1++ is \n"<<*ptr1<<"\n";
ptr1++;
cout<<"value of ptr1++ is \n"<<*ptr1<<"\n";

ptr1--;
cout<<"value of ptr1-- is \n"<<*ptr1<<"\n";
cout<<"Now adding an integer to the pointer\n";
ptr1=ptr1+2;
cout<<"value of ptr1 +2 is \n"<<*ptr1<<"\n";

cout<<"Now ubtraction 1 pointer from another \n";
//ptr1=ptr1+2;

return 0;
}
Previous                             Home                               Next

1 comment:

  1. How to use pointer arithmatic in C++
    //========================
    //Program in c to learn pointer in C, pointerarithmatic2.cpp
    How to use pointer arithmatic in C++
    //========================
    //Program in c to learn pointer in C, pointerarithmatic2.cpp
    How to use pointer arithmatic in C++
    //========================
    //Program in c to learn pointer in C, pointerarithmatic2.cpp
    How to use pointer arithmatic in C++
    //========================
    //Program in c to learn pointer in C, pointerarithmatic2.cpp
    How to use pointer arithmatic in C++
    //========================
    //Program in c to learn pointer in C, pointerarithmatic2.cpp
    How to use pointer arithmatic in C++
    //========================
    //Program in c to learn pointer in C, pointerarithmatic2.cpp
    How to use pointer arithmatic in C++
    //========================
    //Program in c to learn pointer in C, pointerarithmatic2.cpp

    ReplyDelete