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

220
Vistas
Weird output of simple expression in C, why?

I am using TurboC++. I write the following expression which is not resulting in proper evaluation, am I missing some concept behind it?

int c=300*300/300;
printf("%d",c);

The output is

81

Why?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

300*300 is 90000.

Assuming int is 16bit, you have overflowed.

The overflow wraps around, giving you: 24464.

24465/300 = 81.55

Do not rely on this. It is undefined behavior.

over 4 years ago · Santiago Trujillo Denunciar

0

The evaluation of 300 * 300 / 300 happens from left to right.

300 * 300 overflows a 16 bit signed integral type (an int in Turbo C++ is 16 bit). As the computation will take place in signed arithmetic, the result is undefined.

What's happening is 300 * 300 is wrapping round to give you 24464. (24464 + 32768 + 32768 = 90000).

24464 / 300 is 81 in integer division.

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