Delion
asked on
Easy (I hope) Visual C++ question- Why NEW?
Ok- hopefully, this is an easy question. I'm trying to learn Visual C++ 6.0 from books (Couldn't find a local course on it that wasn't full) and I've got a few questions. For now, though, here's one-
Why use the NEW command when initializing variables and classes? For example, why say "new int a;" instead of "int a;"?
I've consulted 3 books, and so far the only difference that they tell me is that I've got to use the delete command after I'm done with them or else I get a memory leak. This seems more like a disadvantage than anything else, so what advantages does the NEW command provide?
-Delion
Why use the NEW command when initializing variables and classes? For example, why say "new int a;" instead of "int a;"?
I've consulted 3 books, and so far the only difference that they tell me is that I've got to use the delete command after I'm done with them or else I get a memory leak. This seems more like a disadvantage than anything else, so what advantages does the NEW command provide?
-Delion
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adjusted points to 30
char TextArray[1000];
but what if the file is more than 1000 characters long? Well, you could declarre it to be 10000 characters long, but that might still not be enough. What is more, if the file is short, say only 100 characters, then 10000 characters would be a terrible waste of space. So you can use "new" to allcoate an array of just the right size once you learn the needed size at run-time.