Why is it that in this statement "c = '\t'" is not "c == '\t'" (an additional equal sign). I read an explanation that it is because \t is a visual representation of the tab character.

Isn't \n and ' ' also visual representations of a newline and space character respectively?

if (c == ' ' || c == '\n' || c = '\t')

Recommended Answers

All 2 Replies

Why is it that in this statement "c = '\t'" is not "c == '\t'" (an additional equal sign). I read an explanation that it is because \t is a visual representation of the tab character.

Isn't \n and ' ' also visual representations of a newline and space character respectively?

if (c == ' ' || c == '\n' || c = '\t')

Incorrect! It should be c == '\t' There's nothing special about the '\t' c = '\t' will assign a tab to variable c

In addition to what Aia said about c = '\t' :
The assignment operator produces a value, values can be used to control an if-statement, like in your example. That's the reason why your code will still compile and run. In C every zero and non-zero value are respectively equivalent for false and true, the '\t' character has a non-zero value thus is equivalent for true.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.