C Syntax Basics

C Program Structure

Every C program begins execution from the main() function. It serves as the entry point for the program. To use functions like printf or scanf, you must include the appropriate header file—most commonly stdio.h, which stands for Standard Input/Output.

The basic structure of a C program includes:

  • Preprocessor Directive: #include <stdio.h> tells the compiler to include the standard I/O library
  • Main Function: int main() is where the program starts
  • Statements: Code inside is executed line by line
  • Return Statement: return 0; signals that the program ended successfully
Loading...
Output:

Print Output

C uses printf() to print output. It is declared in <stdio.h>.

Loading...
Output:

Statements and Semicolons

Each statement in C must end with a semicolon (;). Forgetting a semicolon leads to compilation errors.

Loading...
Output:

Curly Braces Define Blocks

C uses {} to group multiple statements into a block. This applies to functions, conditionals, and loops.

Loading...
Output:

Case Sensitivity

C is case-sensitive. Variables like value and Value are treated as separate identifiers.

Loading...
Output:

Comments in C

Use comments to describe what your code does. C supports:

// Single-line comment
/* Multi-line
   comment */

Whitespace and Formatting

The C compiler ignores whitespace (spaces, tabs, newlines), but proper formatting makes code readable and maintainable.

Loading...
Output:

Practice Question

Which of the following will cause a compilation error? Send your answer to the AI Chatbot

A. int number = 10;
B. printf("Result is: %d", number)
C. return 0;
Loading...
Output:

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic