How to find the length (size) of an int array in C++

2 Answers

0 votes
#include <iostream>

using namespace std;

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

	int size = sizeof(arr) / sizeof(arr[0]);

	cout << "size = " << size << endl;
		
	return 0;
}


/*
run:

size = 7

*/

 



answered May 24, 2017 by avibootz
0 votes
#include <iostream>

using namespace std;

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

	int size = sizeof(arr) / sizeof(*arr);

	cout << "size = " << size << endl;
		
	return 0;
}


/*
run:

size = 7

*/

 



answered May 24, 2017 by avibootz

Related questions

2 answers 197 views
1 answer 172 views
1 answer 190 views
1 answer 142 views
1 answer 184 views
...