Reputation: 25
I have problem in the following code:
int *ary = new int[2];
ary[0] = 1;
ary[1] = 2;
cout << &ary[0]; //no error
cout << &ary[0] + " " + &ary[1]; //error (expression must have integral or unscoped enum type )
I cant understand why arise error using pointer value with string(integral)
Upvotes: 0
Views: 95
Reputation: 170055
cout
"streams" data into the standard output using the <<
operator. Not the +
operator.
cout << &ary[0] << " " << &ary[1];
The way you wrote it before attempted to add 2 int*
with a char[2]
, which aren't valid types to add with each other.
Upvotes: 3