DSA 1.12 - pointer to structure

PHOTO EMBED

Sun Mar 05 2023 17:37:26 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c++

#include <iostream>
using namespace std;

struct rectangle
{
    int length;
    int breadth;
};

int main() {
    
    rectangle *p;
    // in C, struct rectangle *p;
    
    p = new rectangle;
    //in C, p = (struct rectangle *)malloc(sizeof(struct rectangle));
    
    p->length = 15;
    p->breadth= 7;
    
    cout << "length : "<<p->length<<endl;
    cout << "breadth : "<<p->breadth<<endl;
    
    
 return 0;
}
content_copyCOPY

to create object of rectangle in heap memory