|
|
|
|
|
|
|
|
Just use a std::vector<int> instead of an int[] array. |
Well "it works" - and that usually means it's dodgy! |
Is there a way to pass a direct value to a function that expects an Int Array as its input? |
|
|
If I don't use Delete to remove this down the line, does that mean every time I run this program I take memory from the OS and never give it back? I'm just curious. |
I have a question about using New Int. |
I have a question about using New Int. That's fine but the way you are going about it is 'dodgy' and lucky at best. There's absolutely no reason to go in that direction because effectively you are hard-coding a solution looking for a problem that will probably never exist. e.g. how are you going to change/input values to the dodgy array. It can be done but it's pointless when the orthodox ways are reliable and simple as long as you understand/follow the (C) rules/intent. Memory is 'given back' when the program exits, so a delete is not needed. I can't think of a situation where a memory leak in your case would be even remotely significant. Upgrade your multi-tasking machine if the few bytes involved are going to be a drama/out of memory crash. There is a proper way to declare, populate and pass/return C-style arrays. BTW The old wives <vector>'s stuff isn't constructive, just another red herring. For simple jobs and especially in understanding the foundations of STL containers in software engineering and/or even legacy code C-arrays are an important and useful part of C++. |
|
|
(123) 456-7890 (425) 364-7586 Ouch! |
|
|
123-456-7890 Invalid number Change the 5th number to : 8 123-486-7890 Program ended with exit code: 0 |
|
|
(123) 456-7890 (314) 159-2653 |
|
|