0

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')

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by mvmalderen
0

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

0

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.

This topic has been dead for over six months. 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.