HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to CVariablesData TypesOperatorsStringsArraysConditions (if / switch)Loops (for / while)FunctionsPointers
REFERENCE
📖 Overview
🖥️ Output & Input
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array
🔁 Condition & Loop
🧩 Function
👉 Pointer
C›Introduction to C

Introduction to C

First step into C, the foundation of systems: program structure (#include/main), printing with printf, and variables.

Simple enough for a 5-year-old to understand

Structure of a C program

Every C program includes libraries with #include and runs from the main() function. printf writes to the screen.

Your first program
1
#include <stdio.h>
Input/output library (for printf).
ImportInput/output library (for printf).
2
int main() {
The program starts here.
FunctionThe program starts here.
3
printf("Hello!\n");
Writer. \n = new line (not automatic!).
Output / InputWriter. \n = new line (not automatic!).
4
return 0;
Program finished successfully.
CodeProgram finished successfully.
5
}
End of main.
FunctionEnd of main.
ImportFunctionOutput / InputCode
💡 Hint: In C, printf does NOT add a new line automatically; if you don't write \n, the texts will appear side by side.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.What is written to move to the next line in printf in C?
2.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

C was developed by Dennis Ritchie in 1972 to write the Unix operating system. Underneath almost everything you use today lies C: the Linux kernel, a major part of Windows, Python and PHP interpreters, databases, and embedded device software.

What sets C apart from other languages is that it gives you direct control over memory. You determine how many bytes a variable takes up in memory, where it resides, and when it is freed. This power is also C's greatest danger: the language does not protect you from mistakes.

Learning C means learning how a computer works. You only understand what happens behind the scenes when adding an element to a list in Python after learning C. That is why C is a valuable lesson even if you never use it in practice.

What you will learn

  • what the include directive does
  • why the main function returns an int
  • printing to the screen with printf
  • that compilation and execution are two separate steps
  • why the semicolon is mandatory

Who is this for?

  • Those who want to work on embedded systems, drivers, or operating systems
  • Students taking data structures and algorithms courses at university
  • Those who know a high-level language and wonder what lies beneath it

When to use?

C is used everywhere working close to the hardware: microcontrollers, kernel modules, audio and video codecs, and performance-critical parts of game engines.

It is also the common language for writing extensions for other languages. The fast part of Python's NumPy library is written in C; the Python side simply calls it.

Common mistakes

Wrong

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

Since stdio.h is not included, the compiler does not know what printf is. GCC gives the warning "implicit declaration of function 'printf'"; in newer standards, this is a direct error. The corresponding header file must be included for every library function.

Correct

#include <stdio.h>

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

Wrong

#include <stdio.h>

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

There is no semicolon at the end of the printf line. The error message comes as "expected ';' before 'return'", and the point to note is this: the compiler reports the error on the NEXT line. In C, the semicolon is not an end-of-line marker, but an end-of-statement marker.

Correct

#include <stdio.h>

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

Wrong

#include <stdio.h>

void main() {
    printf("Hello");
}

Does the main function return int by standard? void main is non-standard and causes errors in some compilers. Also, since there is no newline character at the end of the text, the output sticks to the command line in the terminal. The returned zero informs the operating system that the program has finished successfully.

Correct

#include <stdio.h>

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

Frequently asked questions

Are C and C++ the same language?

No. C++ adds classes, templates, and a much larger standard library on top of C. A valid C program will usually compile with a C++ compiler as well, but the reverse is not true. C is a much smaller language; the entire standard is a few hundred pages.

What does compiling mean?

Translating the text file you wrote into machine code that the processor can understand. In Python, you run the file directly; in C, you first compile it with the command gcc program.c to produce an executable file, and then you run it. When the code changes, you need to recompile it.

What is the backslash n inside printf?

The newline character. printf does not automatically move to the next line after printing, so you need to add the newline yourself. These notations starting with a backslash are called escape sequences; backslash t is used for a tab, and two backslashes are used for a literal backslash itself.

Summary

Every C program starts with a main function and main returns an int.

You must include the header file before using a library function.

Every statement ends with a semicolon; the compiler reports a missing semicolon on the next line.

printf does not add a newline, you add it yourself.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code