Bytebook Compiler

Getting Started

Syntax, Output & Comments

The grammar rules of C, how printf prints text and numbers, escape sequences, and how to comment code.

3 min read4 runnable examples4-question quiz

C syntax rules

C is strict about grammar. Five rules cover almost every beginner error:

  1. Every statement ends with a semicolon ;.
  2. C is case-sensitive — printf works, Printf does not.
  3. Blocks use curly braces { }.
  4. Whitespace is ignored — indent for humans, not for the compiler.
  5. Text goes in double quotes "..."; a single character goes in single quotes 'A'.

Printing with printf

printf (print formatted) writes text to the screen. Text without \n stays on the same line:

C
#include <stdio.h>

int main(void) {
    printf("Learning ");
    printf("C is fun.");
    printf("\n");
    printf("This is on a new line.\n");
    return 0;
}
Output
Learning C is fun.
This is on a new line.

To print numbers, put a format specifier in the text and pass the value after it. %d prints an integer:

C
#include <stdio.h>

int main(void) {
    int marks = 92;
    printf("Marks: %d\n", marks);
    printf("%d + %d = %d\n", 7, 5, 7 + 5);
    return 0;
}
Output
Marks: 92
7 + 5 = 12

You will meet all the format specifiers in the next lesson.

Escape sequences

A backslash \ inside a string starts an escape sequence — a special character you cannot type directly.

Sequence Meaning
\n New line
\t Horizontal tab
\\ A backslash
\" A double quote inside a string
\' A single quote
\0 The null character (ends every string)
%% A percent sign (inside printf only)
C
#include <stdio.h>

int main(void) {
    printf("Name\tMarks\n");
    printf("Asha\t95\n");
    printf("Ravi\t88\n");
    printf("She said \"C is easy\" and scored 100%%.\n");
    printf("Path: C:\\Users\\asha\n");
    return 0;
}
Output
Name	Marks
Asha	95
Ravi	88
She said "C is easy" and scored 100%.
Path: C:\Users\asha

puts and putchar

Two simpler output functions are also in stdio.h:

  • puts("text") prints a string and adds a newline automatically.
  • putchar('A') prints exactly one character.
C
#include <stdio.h>

int main(void) {
    puts("Hello from puts");
    putchar('O');
    putchar('K');
    putchar('\n');
    return 0;
}
Output
Hello from puts
OK

Comments

Comments are notes for humans. The compiler ignores them completely.

C
// A single-line comment runs to the end of the line.

/* A multi-line comment
   can span several lines. */

int total = 0; // comments can follow code too

Test yourself

4 questions · pick an answer to check it instantly

  1. 1

    What is printed by printf("A\tB\nC");?

  2. 2

    How do you print a percent sign with printf?

  3. 3

    Which statement about C is true?

  4. 4

    What does puts("Hi"); do differently from printf("Hi");?