Answers for "how to use array without size in c++"

C++
0

how to use array without size in c++

#include <iostream>

int main()
{
	//Create a user input size
	int size;
	std::cout << "Enter Size Of Array : ";
	std::cin >> size;

	//Create the array with the size the user input
	int *myArray = new int[size];

	//Populate the array with whatever you like..
	for(int i = 0; i < size; ++i)
	{
		myArray[i] = rand() % 10;
	}

	//Display whats in the array...
	for(int i = 0; i < size; ++i)
	{
		std::cout << "Item In Element " << i << " of the array = : " << myArray[i] << std::endl;
	}

	//Delete the array
	delete[] myArray;

	return 0;
}
Posted by: Guest on July-18-2021

Browse Popular Code Answers by Language