views:

156

answers:

4

I have an array of double pointers, but every time I try do print one of the values the address gets printed. How do I print the actual value?

cout << arr[i] ? cout << &arr[i] ? they both print the address

Does anyone know?

+5  A: 

If it's really an array of (initialized) double pointers, i.e.:

double *arr[] = ...
// Initialize individual values

all you need is:

cout << *arr[i];
Matthew Flaschen
+1  A: 

cout << *(arr[i]) will print the value.

Anatoly Fayngelerin
A: 

If "arr" is declared as

double* arr[..];

Then you would use:

cout << *(arr[i])
Jay Walker
A: 

cout << *(arr[i]);

Andreas Bonini
don't need parens.
Potatoswatter
@Potatoswatter. The compiler might not, and technically neither do I, because I can remember the operator precedence if I have to. But they certainly improve things.
Steve Jessop
Andreas Bonini