#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
void RandomArrayFill(int* array, int size)
{
//int* array = new int[size];
cout << "Creating and filling the array with integers..." << endl;
for(int i = 0; i< size; ++i)
{
array[i] = rand() % 101;
}
cout << "Array = {";
for(int i = 0; i < size; ++i)
{
cout << array[i] << " ";
}
cout << "}" << endl;
}
int main()
{
srand((unsigned)time(0));
int size;
cout << "Enter Size: ";
cin >> size;
int* newArray = new int[size];
RandomArrayFill(newArray, size);
delete[] newArray;
newArray = 0;
}
invisi 0 Light Poster
Recommended Answers
Jump to PostIf you are using UNIX, you can use valgrind to check for memory leaks. You need to add --tool=memcheck on the command line to check for leaks.
Jump to Postalso in the first program there is no memory leak.
Are you sure. His program is tricky in a sense that there is a memory
leak. His function is definitely not doing what he thinks its doing.One way to tell if you have memory leak is to see …
Jump to Post>In your function, you allocate new memory for the array
>that is passed, which already has been allocated memory.I suppose he has commented that line.
Hence technically, there are no memory leaks in the first program.OP>Why is that anyone know?
That is because the .size() member …
All 9 Replies
invisi 0 Light Poster
Topi Ojala 2 Junior Poster in Training
NathanOliver 429 Veteran Poster Featured Poster
GDICommander 54 Posting Whiz in Training
mrnutty 761 Senior Poster
Tom Gunn 1,164 Practically a Master Poster
siddhant3s 1,429 Practically a Posting Shark
mrnutty 761 Senior Poster
invisi 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.