Alright, let's get started! You have your VS Code text editor ready and your GCC compiler installed. Together, these two are like a dynamic duo, ready to achieve great things!
Step 1: Launching VS Code 🚀
If VS Code is already open, close it. Relaunch it so that it takes into account the new compiler that you have just installed.
Step 2: Creating a New File 📝
- In VS Code, in the upper left corner, click File and New File. You will see a new blank white window open, ready for your great ideas.
- Now click on File again, then Save As.
- In the window that opens, choose where you want to save your file.
- Name your file
premier_programme.cand make sure to give it the extension.c. Press on Save.
Step 3: Write the code 💻
Type the following code into your freshly created file:
#include <stdio.h>
int main() { printf("Hello, World!n"); return 0; }
Step 4: Compiling 🎩✨
Open VS Code's built-in terminal (go to View > Terminal or use the shortcut Ctrl+`). In this terminal, type the following command:
gcc premier_programme.c -o mon_programme
Step 5: Launching the program 🚀
Type in the terminal:
./my program
You should see the message “Hello, World!” – there you go, you have sent your very first message to the world of C programming!
And now, let's decipher it together:
#include <stdio.h>: This is an instruction for the compiler. She tells him to include a file calledstdio.h, which contains the functions necessary for display.- int main() { … }: This is the heart of your program. All C programs start with a main function. This is where it all begins and ends. int indicates that this function will return an integer. Here it returns 0 when the program terminates successfully.
- printf(“Hello, World!n”); : printf is a function that prints text on the screen. “Hello, World!n” is the text that will be displayed, and n is a special character that creates a new line.
- return 0; : This indicates the end of the main function and that the program has completed successfully.
🔍 Little note on braces { ... } : They indicate where the content of the function begins and ends main. Everything inside is what the program does.
In summary : You've written a piece of code that tells the computer to display "Hello, World!" on the screen, and it completes successfully. Congratulations, that's your first step into the world of C programming!
Ready for what’s next? Let's go!