This episode builds the foundation of C syntax: variable declarations and basic data types, a complete program structure with the main function, statements, code blocks, comments, and formatting rules. You will also assemble, run, and do some simple debugging.

Now that you understand the architecture behind C, it's time to write code that actually compiles. Episode 3 builds the basic syntax: how a C program is structured, how variables are declared, and how good formatting rules are applied.
C's syntax is quite concise compared to modern languages. There are only a few keywords, and almost every feature is built from combinations of types, functions, and pointers. This simplicity demands precision: one missing semicolon can change the entire meaning of a program.
By the end of this episode, you will be able to assemble a complete C program, compile it with warning flags, run it, and read error messages with confidence.
The smallest valid C program consists of a single main function. Execution always starts from this function. Consider the following structure:
cat > struktur.c <<'EOF'
#include <stdio.h>
int main(void) {
printf("Struktur program C\n");
return 0;
}
EOF
gcc -Wall -Wextra struktur.c -o struktur
./strukturThe first line #include <stdio.h> loads the declarations for standard input-output functions. The main function returns int, and the value 0 indicates the program finished successfully. A non-zero value indicates an error.
The main function has two valid forms. The first form, int main(void), is used when the program does not read arguments. The second form, int main(int argc, char *argv[]), is used to read command-line arguments. The argc variable holds the number of arguments, and argv is an array of strings storing each argument. Both will be covered in more depth in episode 8.
C provides the basic data types familiar from many languages:
int: whole numbers, usually 4 bytes.char: a single character or one byte.float and double: fractional numbers._Bool: true or false values, used via bool from <stdbool.h>.void: indicates no value.Every variable must be declared with a type before use. Type sizes can vary slightly across platforms, so C provides types from <stdint.h> like int32_t and uint64_t whose sizes are guaranteed.
Literals like 42, 3.14, and 'A' are raw values in code. You can also define named constants with the const keyword:
cat > variabel.c <<'EOF'
#include <stdio.h>
int main(void) {
const int umur = 25;
double tinggi = 1.75;
char inisial = 'A';
printf("Umur %d, tinggi %.2f, inisial %c\n", umur, tinggi, inisial);
return 0;
}
EOF
gcc -Wall -Wextra variabel.c -o variabel && ./variabelThe declaration const int umur = 25 makes the value of umur immutable after initialization. Using const for values that genuinely never change is a habit reviewers appreciate.
Every statement ends with a semicolon. Examples of statements: variable declarations, function calls, and assignments. A group of statements enclosed in curly braces is called a code block. Blocks define scope: variables declared inside a block live only within that block.
Comments are not executed by the compiler and serve to explain the intent of code. C supports two styles: single-line comments with // and multi-line comments with /* */. Write comments that explain why a decision was made, not ones that merely repeat what is already visible in the code.
C formatting is not governed by the language, but by community convention. Use 4-space indentation per level, put the opening curly brace at the end of the same line as the declaration, and add spaces around operators. Consistency matters more than any particular style you choose. Automated tools like clang-format can unify the style across a whole team:
clang-format -i variabel.cThe command clang-format -i variabel.c rewrites the file using the default LLVM style. Many projects use a .clang-format file in the repository to enforce a single shared style.
Never compile without warning flags. A healthy habit:
gcc -Wall -Wextra -pedantic -g variabel.c -o variabel
./variabel-pedantic warns about usage of extensions outside the standard, and -g adds debug information. The combination -Wall -Wextra -pedantic -g is the standard used by serious projects.
The compiler reports error locations in the format of file name, line number, and column. For example variabel.c:7:5: error: expected ';'. Read that line, find the cause, and fix it. Warnings don't stop compilation, but they almost always signal hidden bugs; treat warnings as errors by adding -Werror.
For interactive debugging, run the program under gdb and step through line by line:
gdb -q ./variabelInside gdb, type break main to stop at the start of the main function, then next to execute one line and print umur to inspect a variable's value. We'll practice a full session in episode 11.
Key takeaways:
In the next episode 4 we will discuss operators and control flow — arithmetic, bitwise, logical, and ternary operators, if, if-else, and switch conditional statements, for, while, and do-while loops, and break, continue, return, and loop control patterns.