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

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

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

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 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