Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> C Language

C Hello World: Your First Program – A Step‑by‑Step Guide

Below is a classic "Hello World" program written in C, followed by a detailed explanation of each component.

#include <stdio.h>   // Pre‑processor directive
int main(void)       // Main function declaration
{
    printf("Hello World");  // Output the string to the console
    return 0;                // Terminate the program
}

1. Pre‑processor Directive

The #include <stdio.h> directive tells the compiler to incorporate the Standard Input/Output library, where printf is defined. Including the appropriate header file is mandatory before using any function from that library.

Custom header files can also be included in the same way: #include <file‑name.h>. Place all #include statements at the top of your source file.

2. The main Function

Every C program must contain a main function. Common signatures include:

Using int main(void) signifies that the program does not accept command‑line arguments and will return an integer exit status. A return value of 0 indicates successful execution.

3. Code Structure

4. Running a C Program

Below are the typical steps to create, compile, and run a C program in a common IDE:

  1. Create a new project and choose a C/C++ source file.
  2. Configure the file path and name (ending with .c).
  3. Save the file and click "Build & Run".

Once compiled, the output window should display:

Hello, World!

5. Summary

C Language

  1. Building Your First FPGA: LED Blink Tutorial (VHDL & Verilog)
  2. C# Hello World – Building Your First C# Application
  3. Java Hello World: Your First Program
  4. Your First VHDL Program: A Step‑by‑Step Hello World Tutorial
  5. C++ Hello World Tutorial: Step‑by‑Step Code, Setup & Explanation
  6. C# Hello World: Building Your First Console Application
  7. calloc() in C: Zero‑Initialized Memory Allocation and a Practical Example
  8. Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program
  9. Hello World: Building Your First Python Application
  10. Understanding Python's Main Function: A Practical Guide to def main()