Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda