I was given some code by my Professor and I had to debug it. I finally found the problem, but I have no idea why it is a problem. Could someone please enlighten me.

Here is the piece of the code that has been corrected:

.
.
.
//Using negative subscripts
	cout<<"\nUsing negative subscripts"<<endl;
	p = a + n-1;
	for (size_t i =0; i < n ; ++i)
		cout << p[-i] << ' ';
		cout<< endl;

Here is the original code piece with the error:

.
.
.
//Using negative subscripts
	cout<<"\nUsing negative subscripts"<<endl;
	p = a + n-1;
	for (size_t i =0; i < n ; ++i)
		cout << p[-i] << '  ';     //   <------ There is an extra space.
		cout<< endl;

Why does it display what it does, instead of just add two spaces between each number? :-/

..aren't single inverted commas just for char variables? Maybe that would cause a problem because the compiler would be expecting one character and receives two. Just a guess :-/

that is the problem

cout << 'a';  //  good
cout << ' ';  //  good
cout << 'ab';  //  bad
cout << '  ';  // bad

Edited 7 Years Ago by NathanOliver: n/a

This question has already been answered. Start a new discussion instead.