Wednesday, 2 July 2014

C++ program to illustrate subtracting one pointer from another


Here is a C++ program to illustrate subtracting one pointer from another


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int x[5]={10,20,30,40,50},*p,*q;
    p=&x[1];
    q=&x[4];
    cout<<"x["<<q-p<<"] = "<<x[q-p]<<endl;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment