2.1 Hello, World

What to do

Thanks to Professor Brian Kernighan, β€œHello, world” has been implemented in hundreds of languages. Let’s add your implementation to the list!

  • In a file called hello.c, in a folder called world, implement a program in C that prints hello, world\n, and that’s it!

Advice

Hint: Here’s the actual code you should write! (Quite the hint, huh?) Best to type it yourself, though, rather than copy/paste, so that you start to develop some β€œmuscle memory” for writing code.

#include <stdio.h>

int main(void)
{
    printf("hello, world\n");
}

How to Begin

Click and accept the Homework Link.

Start by clicking inside your terminal window, then execute cd by itself. You should find that its β€œprompt” resembles the below.

$

Next execute

mkdir world

This makes a folder called world in (the default or β€œroot” directory of) your codespace.

Then execute

cd world

This changes directories into that folder. You should now see your terminal prompt as world/ $. You can now execute

touch hello.c

to create a file called hello.c in which you can write your code.

Recall that you can compile hello.c with:

make hello

If you don’t see an error message, it compiled successfully! You can confirm as much with

ls

which should list not only hello.c (which is source code) but also hello (which is machine code).

If you do see an error message, try to fix your code and try to compile it again. If you don’t understand the error message, seek help.

Once your code compiles successfully, you can execute your program with:

./hello

How to Submit

  • Click and accept the Homework Link on the homework main page for this week.
  • Complete each assignment for this week in the Github Codespaces environment.
  • Save and click β€œCommit changes”.
  • The autograder runs automatically; see the Actions tab for feedback.