Hello, i just wanted some input from professionals on whether or not my code is efficient or proper. its a simple program using pointers and dynamic memory allocation, and using functions. It outputs and compiles exactly how i wanted it to, i just wanted insight if its proper? also i would like to know if im using
1 2
delete[] dArray;
dArray = NULL;
correctly in the right place. i didnt know if i should use it in main() or in one of my function definitions.
For your fillArray and printArray functions I would be consistent on whether or not I passed the array size by value or reference. Since the parameter is an int, I'd probably just go with pass by value for both. So instead of void fillArray(int*, int&); I'd say void fillArray(int*, int); and update the function definitions accordingly.
EDIT: Misinterpreted the purpose of the "numberOfElements" parameter; assumed it was used for bounds checking
If you wanted to go nuts on your const correctness, you could const both the data you're pointing at and the pointer itself.
I think its probably good to get in the habit of using const where you can ( i.e., const pointers, pointers to const or both). It just seems like neater code.