What Does the Exclamation Mark Mean in This Line of C18 Code?

Status
Not open for further replies.
Hi there,
It means 'not equal to'. So the succeeding code (in the while loop) will repeat as long as switch_pin is not equal to 1 (ie while the pin logic value is low).
Hope that helps!
Ant
 
in C/C++/C# there are two negation operators

! negates logic
~ negates on the bit level
 
Depends on what the voice inside of your head tells you! Both answers are right. While not equal to something would be how I do it. While I'm not dry , keep using the towel vs. When I'm dry don't use the towel.

Something to think about!
 
Ok, thanks. So (Switch_Pin == 0); would do it.

Cheers.

Some coders would write the comparison like this: (0 == Switch_Pin)
So if you accidentally mistype it: (0 = Switch_Pin)
The compiler will detect that and give you an errror, but if you mistype it: (Switch_Pin = 0)
The compiler cannot detect the error you made.

And,
(Switch_Pin == 0)
is not the same as:
(Switch_Pin != 1)

They may produce the same behavior depending how the variable is defined.. and depending on the compiler.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…