#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
Code | Explanation |
---|---|
#include <stdio.h> | Load the I/O library |
Code | Explanation |
---|---|
int main(void) { ... } | Code entry-point |
Code | Explanation |
---|---|
printf("Hello, world!\n"); | Displays the line “Hello, world!” |
Code | Explanation |
---|---|
return 0; | Return from the function(with a value of 0) |
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
Type | Example |
---|---|
Entry-point | int main { ... } |
Strings | "Hello, world!\n" |
Functions | printf(...) |
Semicolons | ; |
EXERCISE
Write a C program to print out “Hello”, followed by your name.
Wait, how do I write the code?
Write a C program to print out “Hello”, followed by your name.
Open a code editor
Write a C program to print out “Hello”, followed by your name.
Load the C library for input and output.
#include <stdio.h>
Write a C program to print out “Hello”, followed by your name.
Create the entry-point code
#include <stdio.h>
int main(void) {
return 0;
};
Write a C program to print out “Hello”, followed by your name.
Write a string that says “Hello”, and your name.
Hint: Use printf()
Don’t forget your semicolons!
#include <stdio.h>
int main(void) {
printf("Hello, Andrew!");
return 0;
}
Write a C program to print out “Hello”, followed by your name.
Save the source code file.
Name it whatever you like, but end it with .c
e.g. hello.c
Write a C program to print out “Hello”, followed by your name.
Compile the file.
In a terminal, navigate to the file and compile it.
e.g. gcc hello.c -o hello
Write a C program to print out “Hello”, followed by your name.
Execute the file!
$> ./hello
Hello, Andrew!