Skip to content

C Getting Started

William L edited this page Sep 15, 2019 · 1 revision

Getting Started with C

The first thing you need to know how to do in C is to create the main function, which will be executed when you run your program.

You also (almost) always will want to include stdio.h at the top of your program (outside of your function), which will allow you to output to the console, and receive input from the console.

You can do this with

#include <stdio.h>

Next, to create our main function, we can do:

int main() {
    /*Your code goes here*/
    return 0; /*We will use this, for now, to tell us that our program works, but this is not required*/
}

Now, we want to make something happen when our program is ran, so, we will output to the console. We can use printf for this.

You should note that at the end of every line of code, you need to add a ; to tell C that it is the end of the line.

To output Hello World! to the console, we can do printf("Hello World!")

All together now:

#include <stdio.h>

int main() {
    printf("Hello World!");
    return 0; /*We will use this, for now, to tell us that our program works, but this is not required*/
}

Output:

Hello World!

🥇 Horray! You have completed the introduction to C!

Next Article (Variables)

Languages

Other

Clone this wiki locally