Ch 2 · Your First C Program · C
Topic 2 of 13 in C — Complete Tutorial (Beginner) — 2 lessons.
Hello World!
Every C program starts in a function called main. To print text we use printf, which lives in the standard input/output library — so we include it at the top with #include <stdio.h>. The \n inside the text means "new line." Every statement ends with a semicolon ;, and main ends with return 0;, which tells the system the program finished successfully.
printf and Format Specifiers
printf does more than print fixed text — it can insert values using format specifiers, which are placeholders starting with %. Use %d for an integer, %f for a decimal (float/double), %c for a single character, and %s for a string. You write the text with the placeholders, then list the values to fill them in, in order. The \n gives a new line wherever you want one.