Using Arrow Operator with Pointers to Access Structure




This video tutorial explains how to use pointers and structures together in your program.
You will learn how to declare a pointer to store the address of a structure variable, how to access the structure members using pointer, what is arrow operator in detail with examples.

source code for this tutorial

#include <iostream>

using namespace std;

struct student{
    int rollno;
    char sex;
};

int main()
{
    student anil;
    student *anilptr;

    anilptr = &anil;

    anil.rollno = 1234;
    anilptr->sex = 'm';

    cout << anilptr -> rollno <<endl;

    cout << anil.sex <<endl;

    return 0;
}