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

219
Vistas
What is wrong with the following code segment, and isn't default switch mandatory for "switch" loops?

I am tired of my university, my midterm exams and I am tired of thinking what the hell is wrong here.

double n;
n = 3.5; // line 2
switch( n){
case 2.5 : printf(“High”); break;
case 0.5 : printf(”Low”); break;}

In general, I thought default statement is missing because n is 3.5 and every switch statement we wrote included a default statement.

Options are:

  • I)default statement is missing (What I ticked.)

    II)there is an error in line 2

    III)semi colon is missing at the end of the switch statement

    IV)double data type cannot be used with switch statement (Correct answer.)

Can anyone explain me why IV is correct answer? Thank you.

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

0

The label default may be omitted in the switch statement. However the case labels shall be of integer type.

So the switch statement is incorrect at least due to incorrect case labels.

Also the expression in the switch statement shall have an integer or an enumeration type.

over 4 years ago · Santiago Trujillo Denunciar

0

switch work on integral values (int, enum).

If you want to "switch" on double values, you will need to use if/else statements.

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