Skip to main content
Logo image

Section 3.1 Hello, World!

A Hello World program is a computer program that displays Hello, World! to the user. It is often the very first program students write when they are introduced to a new programming language.

admin.....open in new window

Activity 3.1.

Click on the “Run” button in the above code window to observe that this C-program indeed outputs Hello, World! to the screen. Now try the following modifications - don’t worry, you can always return to the original program by clicking on “Start Fresh”.
  1. If you haven’t already, click “Close” in the window that displayed the Hello, World! message. Now modify the code so that the computer outputs a greeting to you instead of to the world when you hit “Run” again. For example, you could output Hello, Petra!
  2. Delete the semicolon at the end of the printf(...); line. Then click “Run”. What happens? Put the semicolon back and run the code again to make sure you are back to normal.
  3. Misspell printf on purpose. What happens?
  4. Create a second printf() line, the first one saying Hello, World!, the second one displaying your personal greeting. What do you notice?
  5. Add the two characters ‘\n’ at the end of the first printf() line, just before the closing quotation marks, so that the line now reads:
    printf("Hello, World!\n");
    Run your code and observe the effect. The backslash ‘\’ indicates that rather than text to be printed to the screen, a command follows. In this case, the ‘\n’ is the command to start a new line. Such a command, starting with a backslash, is also called an escape sequence.