Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to write generic print function arrays of numbers in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

template <class BBL> void print(BBL *arr, int size)
{
	for (int i = 0; i < size; i++)
		cout << arr[i] << ' ';
	cout << endl;
}

int main()
{
	int arrint[] = { 7, 3, 9, 2, 1, 8, 1, 5, 4 };

	print(arrint, 9);

	double arrdouble[] = { 3.14, 1.11, 1.21, 5.67, 3.98 };

	print(arrdouble, 5);

	return 0;
}


/*
run:

7 3 9 2 1 8 1 5 4
3.14 1.11 1.21 5.67 3.98

*/

 



answered Aug 1, 2018 by avibootz

Related questions

...