new for struct

struct ListNode {
ListNode* next;
int data;
};

The first constructor –new ListNode- without parenthesis – provides what is called default initialization (do not confuse with default constructor). Default initialization leaves the values of fundamental types (int, double, etc) uninitialized, i.e. arbitrary. Therefore, with new ListNode; you get uninitialized chunk of memory with arbitrary values in the fields.

The second constructor –new ListNode() with parenthesis – provides what is called value initialization. Value initialization zeros fundamental types. Therefore, with new ListNode(); you get zero-initialized chunk of memory – all fields in this case will be zeros.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s