C++ programmers please help
Go to solution
Solved by Unimportant,
3 hours ago, AndrewZ said:<snip>
The index operator [] already dereferences the indexed element. Dereferencing it again results in the error.
if(scores[k] > scores[k+1])
You can also do arithmetic directly on pointers. So if you need a pointer there is no need to use index operator [] to dereference a index and then take it's address again.
swap(scores + k, scores + k + 1);
Although you should be using std::swap instead of rolling your own unless there's a good reason for it.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now