0

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)

Maroun
  • 94,125
  • 30
  • 188
  • 241
M.K Che
  • 25
  • 6
  • What you are doing is adding unrelated pointers together, not creating strings. Perhaps you should [find a good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and start from the beginning? – Some programmer dude Dec 29 '16 at 08:40
  • yes. I mix up with java. anyway thanks – M.K Che Dec 29 '16 at 09:03

1 Answers1

3

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.

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458