Loading...
Loading...

C Hello World Tutorial

This tutorial demonstrates how to create and run your first C program, the famous "Hello, World!" example. It introduces the basics of C syntax and program execution.

1. Write Your First C Program

Create a new file named hello.c and add the following code:

#include <stdio.h>

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

This simple program uses the printf function to print "Hello, World!" to the console.

2. Compile the Program

Use a C compiler to compile your program. For example, if you're using GCC:

gcc hello.c -o hello

This command compiles hello.c into an executable named hello.

3. Run the Program

Execute the compiled program using:

./hello

You should see the output:

Hello, World!

4. Explanation of the Code

  • #include <stdio.h>: Includes the standard input/output library.
  • int main(): Defines the main function, the entry point of the program.
  • printf: Prints the specified message to the console.
  • return 0;: Indicates that the program executed successfully.

5. Conclusion

Congratulations! You’ve written and run your first C program. This "Hello, World!" program is the foundation for learning more advanced C concepts.

0 Interaction
2.4K Views
Views
47 Likes
×
×
🍪 CookieConsent@Ptutorials:~

Welcome to Ptutorials

Note: We aim to make learning easier by sharing top-quality tutorials.

We kindly ask that you refrain from posting interactions unrelated to web development, such as political, sports, or other non-web-related content. Please be respectful and interact with other members in a friendly manner. By participating in discussions and providing valuable answers, you can earn points and level up your profile.

$ Allow cookies on this site ? (y/n)

top-home