top of page

Hello World

High Level Languages

To get a good understanding of how programs will generally be started and general C formatting we can write some test code. We will create a program which prints out the text "Hello World" by opening a .c file in our IDE and typing the following:
 

Let's look at a Hello World example written in C piece by piece.

helloworld.png

Using this test code we can take away some notable points.

#include <stdio.h>

The #include statement is used to include a library into the program. This allows us to use functionality of the library and call to it. stdio.h is the standard in and out library for C and will be defined at the beginning of the program. Other libraries can be included using #include <libraryName>

/* Comments */

Wrapping text in /* */ will create multi-line comments which are not read by the compiler. These are useful for leaving behind notes for yourself as well as other developers. Since they are multi-line comments they can be as long and as many lines as you want.

Simply putting // in front of text will create a single-line comment. This comment will end on the next line without the need for an ending terminator.

int main()

Functions can be made and called upon to complete pre-programmed tasks. The main function is always called upon as the first function. Other functions will be called from the main function. This function holds a block of code wrapped in curly braces {}. This code is what is inside of our function and which will execute.

printf("Hello World");

The printf statement is called upon to send text to our standard output. printf will output the contents of the parentheses which define the text. This command is terminated with a semicolon, without doing so would cause an error while compiling. Without including the stdio.h library this code would not execute properly.

return 0;

The return statement will end the program. The following 0 is a status tag for the program. If a program exits with the status 0 it ran successfully, if a program ends in another status (usually -1 for error) something threw the program off from its designated path. Some compilers and IDEs will generally add the return statement automatically.

  • Twitter
  • LinkedIn
  • discord-logo--v2
  • kisspng-github-pages-logo-repository-fork-github-logo-1-magentys-5b69de71b51265

Dragon Eye Intelligence LLC

bottom of page