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

173
Views
¿Cómo genera el siguiente programa `C89` cuando se compila en modo C89 y `C99` cuando se compila en modo C99?

Encontré este programa C de la web:

 #include <stdio.h> int main(){ printf("C%d\n",(int)(90-(-4.5//**/ -4.5))); return 0; }

Lo interesante de este programa es que cuando se compila y ejecuta en modo C89, imprime C89 y cuando se compila y ejecuta en modo C99, imprime C99 . Pero no soy capaz de averiguar cómo funciona este programa.

¿Puede explicar cómo funciona el segundo argumento de printf en el programa anterior?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

C99 permite // comentarios de estilo, C89 no. Entonces, para traducir:

C99:

 printf("C%d\n",(int)(90-(-4.5 /*Some comment stuff*/ -4.5))); // Outputs: 99

C89:

 printf("C%d\n",(int)(90-(-4.5/ -4.5))); /* so we get 90-1 or 89 */
over 4 years ago · Santiago Trujillo Report

0

el comentario de línea // se introduce desde C99. Por lo tanto su código es igual a este en C89

 #include <stdio.h> int main(){ printf("C%d\n",(int)(90-(-4.5/ -4.5))); return 0; } /* 90 - (-4.5 / -4.5) = 89 */

e igual a esto en C99

 #include <stdio.h> int main(){ printf("C%d\n",(int)(90-(-4.5 -4.5))); return 0; } /* 90 - (-4.5 - 4.5) = 99*/
over 4 years ago · Santiago Trujillo Report

0

Debido a que // los comentarios solo existen en C99 y estándares posteriores, el código es equivalente a lo siguiente:

 #include <stdio.h> int main (void) { int vers; #if __STDC_VERSION__ >= 201112L vers = 99; // oops #elif __STDC_VERSION__ >= 199901L vers = 99; #else vers = 90; #endif printf("C%d", vers); return 0; }

El código correcto sería:

 #include <stdio.h> int main (void) { int vers; #if __STDC_VERSION__ >= 201112L vers = 11; #elif __STDC_VERSION__ >= 199901L vers = 99; #else vers = 90; #endif printf("C%d", vers); return 0; }
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!