Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda