Pointer Structure

#include<iostream>
#include<cstdlib>
using namespace std;
struct anik
{
    int age;
    string id;
};
int main()
{
    struct anik r1;
    r1.age = 10;
    r1.id = "18101073";

    struct anik *p;
    p = &r1;

    (*p).age = 16;
    (*p).id = "18101083";

    cout << "Age : " << r1.age << endl;
    cout << "ID : " <<  r1.id << endl;

    cout << endl << endl;
    p -> age = 20;
    p -> id = "18101070";

    cout << "Age : " << r1.age << endl;
    cout << "ID : " <<  r1.id << endl;

    return 0;
}

Comments