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 calledworld
, implement a program in C that printshello, 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)
{
("hello, world\n");
printf}
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.