First C Program

Here's an example of a "Hello, World!" program in C:

#include 

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

Explanation:

  • The #include <stdio.h> line is a preprocessor directive that includes the standard input/output library, which contains functions like printf.
  • The int main() function is the entry point of a C program. It is where the execution of the program begins.
  • printf("Hello, World!\n"); is a function call that prints the text "Hello, World!" to the console. The \n represents a newline character, which adds a line break.
  • The return 0; statement indicates that the program has executed successfully and returns the value 0 to the operating system.

To run this program:

  1. Save the code into a file with a .c extension (e.g., hello.c).
  2. Open a command prompt or terminal.
  3. Navigate to the directory where the file is saved.
  4. Compile the program using a C compiler. For example, if you have GCC installed, run the command: gcc hello.c -o hello.
  5. If the compilation is successful, an executable file named hello (or hello.exe on Windows) will be generated in the same directory.
  6. Run the program by executing the generated executable: ./hello (or hello.exe on Windows).
  7. The program will output "Hello, World!" to the console.

Congratulations! You have successfully written and executed your first "Hello, World!" program in C.