error?!

Hello.
Why does the following code err?

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
int main()
{
    int c = 0;
    cout << c = 0;
    cin.get();
    return 0;
}


Thanks in advance!
Because << has higher precedence than = so line 6 is treated as (cout << c) = 0;.
Put parenthesis around the assignment fixes the error. cout << (c = 0);
Are you trying to output 0? Are you trying to output the value of whatever c is? OR are you trying to output "c = 0"?

Output 0:
cout << "0";

Output whatever c is:
cout << c;

Output "c = 0"
cout << "c = 0";

Hope that helps!
unfortunately not so much maffiq.I know how to produce good output but I am trying to solve the question.

Answer of Peter87 was more to the point.That was what I noticed myself.But (cout << c) return s an ostream object, isn't it?Why am not able to assign to it value 0?
Because you can't assign an integer to an ostream object. It makes no sense anyways, so I'm not sure why you are trying to do that.
because they did it in my exam and I am trying to figure out the complete answer that why it errs.
Topic archived. No new replies allowed.