Posts

Showing posts with the label pointers

Program for function pointer in C++

 Program for function pointer in C++ #include<iostream> using namespace std; class Data { public:   // access specifier int fun(float)  // function defination { cout<<"object created";    // prints the msg between ""      return 10; } };  // end of the class int main() { int (Data::*fp2)(float); Data obj; fp2=&Data::fun; cout<<(obj.*fp2)(11.1); } Output: object created 10

program for pointer to a pointer in C++

Program for pointer to a pointer in C++ #include<iostream> using namespace std; int main() { int *p,**pp; int x; p=&x; //pointer p stores the address of variable x pp=&p; // double pointer stores the addres of pointer p cout<<"the address of x is : "<<p<<endl; //prints the address of variable x cout<<"the address of pointer p is : "<<pp<<endl;//prints the address of pointer p } output: the address of x is : 0x6ffdfc the address of pointer p is : 0x6ffe00