Kunhi
-1
Q:

-> operator

(pointer_name)->(variable_name)
1
// C program to show Arrow operator 
// used in structure 
  
#include <stdio.h> 
#include <stdlib.h> 
  
// Creating the structure 
struct student { 
    char name[80]; 
    int age; 
    float percentage; 
}; 
  
// Creating the structure object 
struct student* emp = NULL; 
  
// Driver code 
int main() 
{ 
    // Assigning memory to struct variable emp 
    emp = (struct student*) 
        malloc(sizeof(struct student)); 
  
    // Assigning value to age variable 
    // of emp using arrow operator 
    emp->age = 18; 
  
    // Printing the assigned value to the variable 
    printf("%d", emp->age); 
  
    return 0; 
} 
2
//we have a class
struct X
{
   void f() {}
   void g() {}
};

typedef void (X::*pointer)();
//ok, let's take a pointer and assign f to it.
pointer somePointer = &X::f;
//now I want to call somePointer. But for that, I need an object
X x;
//now I call the member function on x like this
(x.*somePointer)(); //will call x.f()
//now, suppose x is not an object but a pointer to object
X* px = new X;
//I want to call the memfun pointer on px. I use ->*
(px ->* somePointer)(); //will call px->f();
0

New to Communities?

Join the community