#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 Post— Topi Ojala 2vector sizes are always in unsigned integers, so change the for-iterator i into an unsigned int.
Jump to Post— NathanOliver 429also in the first program there is no memory leak.
Jump to Post— GDICommander 54If 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.
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.