Hey! Could you explain me what the " new " does, what dynamic memory allocation is and how it helps us?
This can help you "link" objects together so when the one changes, the other changes too.
Hello Konstantinos. You use new to instantiate an object in memory. I will try to explain using an example, ok? //Here you have a NEW person, named Peter. Person a = new Person(); a.name = "Peter"; //Here you have the SAME person, not a new one. Person b = a; //Here you have a NEW person. Person c = new Person(); c = a; //Now check it out. b.name = "Paul"; //If you print b.name, it will show "Paul". //If you print a.name, it will show "Paul" as well. //If you print c.name, it will show "Petter". //It happens because b is the same person on a, but c is a new one. c.name = "Stephen" //Now you have a.name as "Paul", b.name as "Paul" and c.name as "Stephen". I hope it helps. See ya.
new alocates memory on the heap to store data. It is memory that has to be manually handled unlike memory on the stack which is handled automatically by the compiler
what it means is most variables that you will use are handled automatically, there memory is allocated by the compiller when you give your variable a type ie float or int it reserves the nessesary amount of memory. For some programs you will have to reserve enough memory for an unknown data quantity this is where new comes in it can adjust its memory allocation to handle the amount of data coming in.
Every answer is welcome.
Thanks for the answer, but what does this mean for the programmers?
how does this help us?
I have tried every way I could find but still I can't display my local images ..what am I doing wrong?
Pls rectify the errors.
I cant understand what the problem here is. Can anyone help me out? the system in sololearn called it an error in test case 1
Izzy the iguana code coach