+ 1
Itâs there another way to write this? HELP
Hello all! To cut things short, from my understanding I understand âmallocâ to be quite similar to roger new constructor? I donât understand it too well and would like to know an alternate way of writing code that doesnât use malloc in it.. in other words, whatâs the equivalent version of writing this code WITHOUT using malloc? stnode = (struct node *)malloc(sizeof(struct node));
2 Answers
+ 3
Assuming a `node` struct had been defined, this creates one pointer of type `node`
node* stnode = new node();
When you're done with it, don't forget to deallocate the memory used for <stnode> pointer.
delete stnode;