close
close

first Drop

Com TW NOw News 2024

Your First C Adventure: Hello World in VS Code
news

Your First C Adventure: Hello World in VS Code

Hello, beginner C programmer! Ready to start your coding journey? Let’s start with the classic “Hello World” program using Visual Studio Code. Don’t worry if you’re new to this – we’ll explain it step by step!

Great job setting up VS Code using the instructions in the official documentation. That’s a great first step! Now that your environment is ready, let’s write some code.

Create a new file in VS Code and save it as “hello.c”. Then type this code from “The Book of C”:

#include 

int main(int argc, char * argvar()) {
    printf("Hello, World!\n");
    return 0;
}

Let’s break this code down and see what each part does:

  1. #include This line tells the compiler to include the standard input/output library, which contains the following information: printf() function we will use.
  2. int main(int argc, char * argvar()) { This line declares the main function, where program execution begins. argc And argvar Parameters allow command line arguments, but we won’t use them in this example.
  3. printf("Hello, World!\n"); This line prints “Hello, World!” on the screen. \n adds a new line after the message.
  4. return 0; This statement indicates that the program has been successfully executed.
  5. } This closing brace marks the end of our main function.

Now that you have written your code, let’s run it:

  1. Click the Run icon in the upper right corner of the editor.

If all went well, you should see “Hello, World!” in your terminal. Congratulations! You’ve just written and run your first C program in VS Code!

Program output

This simple program is your first step toward mastering C. You learned about including libraries, defining the main function, and using printf to output text. These concepts form the foundation for more complex programs you will write in the future.

Now that you’ve got the hang of it, why not experiment a little? Here are some ideas:

  1. Change the message to greet yourself by name.
  2. Try printing multiple lines using different printf statements.
  3. Use escape characters such as tab or \ to print a backslash.

Remember, the key to learning to program is practice and curiosity. Don’t be afraid to make mistakes – that’s how we learn and grow as programmers!

Pro Tip: VS Code has some great features for C programming. Try using breakpoints and the debugger to step through your code line by line!


Happy coding and welcome to the exciting world of C programming with VS Code! I’m starting my journey with you, so let’s learn and grow together. If you have any questions or need any help, feel free to leave a comment below. I’m here to support you every step of the way!