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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,700 questions

57,013 answers

573 users

How to pass int array to function as a pointer in C++

2 Answers

0 votes
#include <iostream>

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

void print(const int* const arr, const int TOTAL) {
	for (int i = 0; i < TOTAL; i++)
		cout << arr[i] << endl;
}

int main()
{
	const int TOTAL = 3;
	int arr[TOTAL] = { 123, 21, 99 };

	print(arr, TOTAL);
	
	return 0;
}

/*
run:

123
21
99

*/

 



answered May 2, 2018 by avibootz
0 votes
#include <iostream>

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

void print(const int* const p, const int TOTAL) {
	for (int i = 0; i < TOTAL; i++)
		cout << *(p + i) << endl;
}

int main()
{
	const int TOTAL = 3;
	int arr[TOTAL] = { 123, 21, 99 };

	print(arr, TOTAL);
	
	return 0;
}

/*
run:

123
21
99

*/

 



answered May 2, 2018 by avibootz

Related questions

2 answers 284 views
1 answer 318 views
3 answers 429 views
1 answer 169 views
1 answer 191 views
1 answer 226 views
...