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

155
Vistas
A beginner's hello world C program?

As I beginner, I typed the following hello world program on Code::Blocks -

#include<stdio.h>
main()
    {
        printf("Hello world \n");
    }

Now, I click on 'Build and Run', and the output screen shows 'Hello world'.

However, the book I am reading from, suggests me to remove certain elements of the program to see what errors occur in the program.

I made 2 changes. First, I removed \n from the program. (The book tells me that without \n, there will be an error running the program) However, when I click on 'Build and Run', the output screen gives me the same output it did when it was without any errors.

The second change I made was removing #include from the program. Even now, the output screen shows the same output it did when it was free from errors.

Why is this happening? Please tell me how to fix this?

The compiler I am using is GNU GCC compiler.

EDIT: As suggested, I added -wall, -wextra, -pedantic. Now, when I click on 'Build and Run', it says cannot find -1-wall, -1-wextra and -1-pedantic and the program doesn't run. How to fix this now?

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

0

Case 1: your book is wrong. Removing \n will never raise any error. \n means newline which will print a new line after Hello World.

Case 2: May be you are not building the code again, because without including the stdio (means standard input/output) you may not invoke printf() function if you use newer C standards (C99, C11). Read more about stdio.h.

Note that, in pre C99 standard if you remove the prototype (#include <stdio.h>) C will automatically provide an implicit declaration for a function. Which will look like this:

int printf();

means, it will take any number of arguments and return int. But in C99 implicit deceleration were removed. So most probably your compiler does not confront C99.

Take a look here, compile fine!

Read more about implicit declarations in c.

EDIT: As AnT mentioned in the comment, removing #include<stdio.h>, the call to printf will "compile" in pre-C99 version of language. However, the call will produce undefined behavior. Variadic functions (like printf) have to be declared with prototype before the call even in C89/90. Otherwise, the behavior is undefined.

over 4 years ago · Santiago Trujillo Denunciar

0

  1. Your program already contains an error. Functions in modern C have to be declared with an explicitly specified return type. Your main() is declared without a return type, which has been illegal since C99.

  2. There are different kinds of "errors". Some errors cause compiler to issue a diagnostic message. Some errors simply make your program behave unpredictably at run time (exhibit undefined behavior). The latter might be harder to detect, since "unpredictable" might look perfectly fine on the first sight.

    In your case removing #include <stdio.h> will trigger a diagnostic message in C99-compiliant compiler, but will lead to mere undefined behavior in C89/90 compiler. Undefined behavior might still produce the same screen output as before.

over 4 years ago · Santiago Trujillo Denunciar

0

You are not seeing any issue by removing \n because '\n' is a new line character. So previously your output was **"Hello World

"** (newline) And now your output is "Hello World" That's why you don't see any difference.

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