learn-c

Learn the C Programming Language!

View the Project on GitHub infection-tag/learn-c

1.2 Hello World: Breakdown

Let’s do a further analysis of helloworld.c:

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

This is the most basic code you can write, but it actually teaches us a lot.

#include <stdio.h>

#include imports a header library, in this case, stdio.h. stdio.h and any other header files include functions, which, for our purpose, are basically just tools you can use for different things.

main() {

This is the main function. As was stated earlier, this is the main tool. This is the implementation, or the code behind the tool.

printf("hello, world\n");

printf is another function who’s purpose is to print what is contained in the quotes on screen. the “\n” at the end is the symbol for newline, which is similar to typing an enter or return key. The semicolon at the end is there to tell the parser that the line is over. While adding semicolons may seem like more of a downside, like many things in C, it will make a lot more sense later on.

Note: Try removing the \n from the end of the file and recompile it. Can you guess what will happen?

}

All this line does is close the implementation of the main function. Whenever you open a bracket in C, you will almost always need to close it.

Previous

Next