C Language track

Lesson 01 · Level 1: Basics

HelloWorld

C program structure, the compilation process and your first output

Level 1: Basics4 min readFree lesson

This is the first unit of C programming. Through the simplest program Experience the cycle of C program skeleton → compilation → execution.

Learning Objectives

  • Understand the basic structure of C programs (#include, main, printf, return).
  • You can compile source files with gcc and run them in the terminal.
  • Escape sequences (\n, \t) and comments can be used.

Why start with “Hello World”?

Even if it is your first time seeing a program, if you succeed in displaying one line on the screen, It is verified at once that the environment (compiler, PATH, Korean encoding) is normal. That's why almost all introductory language books start with this example. Rather than “learning grammar,” the goal is to run through the development cycle.

Key concepts

1) Skeleton of C program

#include <stdio.h>

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

Let's break down each line.

element Meaning
#include <stdio.h> Preprocessing directive to include the standard input/output library (printf) header
int main(void) The entry point function that the operating system calls first. The return type is int
printf("...\n") Print string to standard output (stdout)
return 0; Return exit code 0, indicating to the OS a "normal shutdown"

2) 4 steps of compilation that occur at once

Although the process of turning a single source code file into an executable file is invisible, it consists of four steps.

hello.c hello (executable file)
  │                                                       ▲
│ ① Preprocessing ② Compile ③ Assemble ④ Link │
  └─►  cpp   ─►   cc1     ─►   as       ─►   ld   ──────┘
(#include expansion) (Create assembly) (Object) (Combining libraries)

gcc calls these four steps at once.

3) Escape sequence

These are characters that perform special actions within a string.

notation Meaning
\n line break (newline)
\t tab
\\ backslash itself
\" double quotes
\0 null character (end of string)

4) Comments

//One-line comments (since C99)
/*multiple lines
tin*/

Comments are ignored by the compiler and have no effect on execution.

See as example

Example 1 — ex01_hello.c: Simplest output

#include <stdio.h>
int main(void) {
    printf("Hello, World!\n");
    return 0;
}

Execution result

Hello, World!

Bottom line: If \n is not present, the following prompt will be stuck on the same line: Try deleting \n yourself.

Example 2 — ex02_multiline.c: Multi-line output and tabs

printf("first line\n");
printf("Second line\n");
printf("Separated by tab\t\n");
printf("Print\nmultiple lines\nat once\n");

Execution result

first line
second line
separated by tabs
at once
multiple lines
Print

Key point: Even with printf once, if there are multiple \n, multiple lines will appear.

Example 3 — ex03_comments.c: Comments are not executed

//one line comment
/*printf("This line is not printed.");*/
printf("Comments have no effect on compilation.\n");

Execution result

Comments have no effect on compilation.

Bottom line: Temporarily disabling code is often wrapped in comments.

Looking at it from a different perspective — Cafe ordering analogy

A C program is similar to a cafe order form.

Cafe C code
menu board <stdio.h> header (list of available functions)
Start Order int main(void) {
Order Items printf(...);
Payment completed return 0;

If there are no orders (=main is empty), the cafe will simply close and end.

Common Mistakes

  1. Missing semicolon: Compilation error if ; is not present at the end of printf("hi").
  2. #include missing: When using printf, <stdio.h> is missing → “implicit declaration” warning.
  3. Main uppercase: C is case sensitive. The entry point must be main.
  4. Quotes in printf("hi"): Double quotation marks (") and single quotation marks (') are different ('h' is one character).
  5. Hangul is broken: If the terminal is not UTF-8, it will be broken. Linux/macOS Usually OK.

Cleanup

  • The C source consists of 4 parts: #include, main, main text, and return.
  • Compiled with gcc -o namefile.c, executed with ./name.
  • printf does not automatically wrap lines, so you must use \n directly.
  • Comments have no effect on compilation, so use them freely.
  • The first goal is to refine the environment so that one cycle (creation → build → execution) runs smoothly.

Try it yourself

cd src

gcc -std=c11 -Wall -o ex01 ex01_hello.c && ./ex01
gcc -std=c11 -Wall -o ex02 ex02_multiline.c && ./ex02
gcc -std=c11 -Wall -o ex03 ex03_comments.c && ./ex03

Application:

  1. Delete \n from ex01_hello.c and see how the output changes.
  2. Call printf only once and print 3 lines. (Hint: Line-1\nLine-2\nLine-3\n)

Example files

The runnable files used in this lesson. Copy them into your own project and experiment.

src/ex01_hello.cC
#include <stdio.h>

int main(void) {
    printf("Hello, World!\n");
    return 0;
}
src/ex02_multiline.cC
#include <stdio.h>

int main(void) {
    printf("first line\n");
    printf("Second line\n");
    printf("Separated by tab\t\n");
    printf("Print\nmultiple lines\nat once\n");
    return 0;
}
src/ex03_comments.cC
#include <stdio.h>

/*
 *This program is an example of annotation usage.
 *The compiler ignores the comment.
 */
int main(void) {
    //One-line comment: print message
    printf("Comments have no effect on compilation.\n");

    /*printf("This line is not printed.");*/

    return 0;
}

Assignment

Problem 1

Write a program that accurately prints the following self-introduction.

Name: Hong Gil-dong
Age: 20
Hobby: Coding
  • File name: hw01.c
  • However, only use 3 for printf calls.

Problem 2

Print the following ASCII art: The backslash (\) must be escaped as \\.

  /\_/\
 ( o.o )
  > ^ <
  • File name: hw02.c

Check the correct answer

After writing it yourself, compare it with the reference solution below.

Show the reference solution

Try the assignment yourself first — comparing your attempt with a working solution is where most of the learning happens.

hw01.cC
#include <stdio.h>

int main(void) {
    printf("Name: Hong Gil-dong\n");
    printf("Age: 20\n");
    printf("Hobby: Coding\n");
    return 0;
}
hw02.cC
#include <stdio.h>

int main(void) {
    printf("  /\\_/\\\n");
    printf(" ( o.o )\n");
    printf("  > ^ <\n");
    return 0;
}

Learn this lesson with a mentor

Work through the C Language track on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now