+ 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));

25th Mar 2022, 10:56 AM
Annei ❤️
Annei ❤️ - avatar
2 Antworten
+ 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;
25th Mar 2022, 11:14 AM
Ipang