0

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? :-/

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by vmanes
0

..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 :-/

0

that is the problem

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

Edited by NathanOliver: n/a

1

OK, you found the compile time error.

Now, there's still a potentially fatal logical error to be corrected.

Votes + Comments
Heh.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.