Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
No puedo entender la salida de este código.
#include<stdio.h> int main() { int a=1,i; for(i=0;i<3;i++) switch((++a)-1) { case 0:printf("\nzero"); case 1:printf("%d.one",i+1); case 2:if(i%2==0) printf("\n\t%d.Two",i+1); else printf("\n%d.Two",i+1); default:printf("\t%d.step",i+1); } }

su salida es:

 1.one 1.Two 1.step 2.Two 2.step 3.step

No puedo entender por qué hay seis salidas donde deberían ser tres, supongo.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Porque sin break; declaración, cada caso continuará en el siguiente.

 switch((++a)-1) { case 0:printf("\nzero"); // Without a break;, the next line gets executed as well! case 1:printf("%d.one",i+1); // Execution continues here, printing "%d.one", even though we are in case 0 case 2:if(i%2==0) { printf("\n\t%d.Two",i+1); } else { printf("\n%d.Two",i+1); } // The default will get run as well, for lack of a "break;" default:printf("\t%d.step",i+1); }

Esto debe escribirse correctamente como:

 switch((++a)-1) { case 0: printf("\nzero"); break; case 1: printf("%d.one",i+1); break; case 2: if(i%2==0) { printf("\n\t%d.Two",i+1); } else { printf("\n%d.Two",i+1); } break; default: printf("\t%d.step",i+1); break; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!