Why constructor is needed here?

class Node{
public:
int data;
Node *next;

//Constructor
Node int(d){
data=d;
next=NULL;
}
};

hi @21cs3042,
u need to make new Node with the data this is one of the way you do that

Can’t I do it without a constructor?
If I will only write the below code, will it work?
class Node{
public:
int data;
Node *next;
};

Yes it will work but u need to assign the values by yourself @21cs3042

Ok. Can you give an example

@21cs3042 after making node u can define by (->) operator
like node->data = 5;

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.