Dynamic declaration of structure using pointer

sAksham-Ar published on
1 min, 100 words

Categories: C++

We can dynamically declare sturrcture is C++ using just new and the name of the structure.To access its inner variables we have to use -> instead of . as it is a pointer ,however we can us . with * behind the pointer so that it becomes a structure variable.

using namespace std;
struct boy
    char name[80];
    int age;
int main()
    boy *b1;
    b1= new boy;
    cout<<"Enter name:\n";
    cout<<"Enter age:\n";
    cout<<"Name is: "<<(*b1).name<<" Age is: "<<(*b1).age;
    return 0;