How to print addresses and values of int array elements in C++

1 Answer

0 votes
#include <iostream>

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

int main()
{
	int arr[3] = { 33, 6, 99 };

	for (int i = 0; i < 3; i++)
		cout << "Address: " << (void*)(arr + i)  
		<< " Value: " << *(arr + i) << endl;
	
	return 0;
}

/*
run:

Address: 001CFC58 Value: 33
Address: 001CFC5C Value: 6
Address: 001CFC60 Value: 99

*/

 



answered May 3, 2018 by avibootz
edited May 3, 2018 by avibootz

Related questions

...