OnlineCBT Logo OnlineCBT
C Tutorial
C · LESSON 2

C Program Structure & Hello World

By Ratan Updated: 15 Oct 2026

Understand preprocessor directives (#include <stdio.h>), main() entry point, and printf().

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Read a C program from top to bottom

This chapter turns the first example into a structure you can reuse. A small console program normally contains header inclusions, function definitions, declarations and executable statements. These parts have different jobs; indentation helps people read the program but braces define its blocks.

A complete Hello World

#include 

/* Program entry point */
int main(void) {
    puts("Hello, World!");
    return 0;
}

The #include directive makes declarations from a header available during preprocessing. It does not mean that the entire implementation of the library is pasted into your source. int is the return type of main, and (void) states that this version takes no parameters. The opening and closing braces enclose the function body.

puts prints a string followed by a newline. Its call ends in a semicolon. A preprocessor directive such as #include does not take that semicolon. return 0; communicates successful termination to the environment.

Comments and layout

A block comment begins with /* and ends with */. Modern C also supports // comments until the end of the line. Comments should explain intent, such as why a value is capped; repeating every statement in English makes maintenance harder. Block comments cannot be nested.

Three different errors

  • Syntax: a missing semicolon or unmatched brace prevents translation.
  • Linking: declaring a function but providing no matching definition can produce an undefined-reference error.
  • Logic: printing the wrong message may compile and run successfully, but still fail the requirement.

Read the first compiler diagnostic before changing code. Later diagnostics may be consequences of the same missing punctuation.

Build and expected result

gcc -std=c17 -Wall -Wextra -pedantic hello.c -o hello

Run the executable using your environment's normal command or the editor's Run button. Expected output is one line: Hello, World! The source filename can change; the entry-point function must still be named main in this hosted program.

Practice with answers

  1. Print your course and batch on separate lines. Use two calls to puts; each supplies its own newline.
  2. Can Main replace main? No: identifiers are case-sensitive.
  3. Does a blank line change execution? No, when inserted between tokens normally separated by whitespace. Splitting a string literal across an unescaped newline is different and is invalid.
  4. Remove a closing brace, compile once, and restore it. Locate the block that was left open rather than adding random braces.

हिन्दी में मुख्य बात: header घोषणा देता है, main से execution शुरू होता है, braces block बनाते हैं और semicolon statement खत्म करता है। अगला अध्याय variables और data types को इसी structure में जोड़ेगा।

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat