Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Comparison Warning in VS Code
#include <stdio.h>
int main()
{
    char c='w';
    if((c>110 && c>120)&&(c<120 && c<200))
    printf("true");
    else
    printf("false");
    return 0;
}

This is my code. The code does give output, but vscode gives me a warning that the comparison of characters with constants(like 200, it specifically shows this only for 200), will always be true, but it does execute the code successfully and gives the final result, which is "false". I tried the same code on the on an online compiler, here, the online compiler gives the result without any warnings.

Any reason for this?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You have defined c as a char, which is a signed char as most compilers do by default. The highest value a signed char can take is 127 on common systems. This is always less than 200, and the IDE tells you this fact.

Note: The header file "limits.h" defines minimum and maximum values for standard types. The interesting value is CHAR_MAX that equals SCHAR_MAX in your case.

Warnings by an IDE can differ from warnings by compilers, because they are different beasts. Some are "smarter" than others, however, not producing a warning does not mean that a construct is correct.

over 4 years ago · Santiago Trujillo Report

0

If c is larger than 120, it is always larger than 110. Same is true with 120 and 200. Remove the useless comparison and the warning should disappear.

over 4 years ago · Santiago Trujillo Report

0

There is this problem: You define c as a char which is a signed char. The biggest value that a signed char can hold is 127. So no matter the value, c < 200 is always true.

Also, if c > 120 is true, then c > 110 is also true. The same thing happens. If c < 120 is true then c < 200 is also true.

Also, please do some proper block scope and indentation. If you don't, it will come back to bite you later.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!