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”.- 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 outputHello, Petra!
- 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. - Misspell
printf
on purpose. What happens? - Create a second
printf()
line, the first one sayingHello, World!
, the second one displaying your personal greeting. What do you notice? - 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.