C-Program
Basic Syntax of C
Last Updated on: 3rd Jul 2025 03:35:42 AM
Understanding the basic syntax is the first step toward writing correct and clean C programs. The syntax defines how statements, functions, and blocks should be written for the compiler to understand and execute the program properly.
1. Tokens in C
In C programming, a token is the smallest meaningful unit in the code. The compiler breaks the source code into these tokens for processing.
There are 6 types of tokens in C:
a. Keywords
-
These are reserved words that have predefined meanings in the C language.
-
You cannot use them as variable or function names.
Examples: int
, float
, if
, else
, while
, return
, break
, switch
keyword perpose
int Defines integer type
return Ends a function and returns a value
if , else Used for conditional logic
2. Structure of a C Program
Every C program follows a standard structure. Here's a simple example:
#include <stdio.h> // Preprocessor directive
int main() { // Main function starts
// Code statements go here
return 0; // End of program
}
Breakdown of the Structure:
Section | Description |
---|---|
#include <stdio.h> |
Tells the compiler to include the Standard Input Output header file |
int main() |
Every C program starts with the main function |
{ ... } |
Curly braces define the body of the function |
return 0; |
Ends the program and returns control to the system |
2. Basic Rules of c Syntax :
-
Every statement ends with a semicolon (
;
). -
C is case-sensitive. (
total
andTotal
are different). -
The program starts executing from the
main()
function.
Example – Simple Program Structure
#include <stdio.h>
int main() {
int number = 10; // variable declaration
number = number + 5;
return 0;
}
Summary :
-
Tokens are the building blocks: keywords, identifiers, constants, operators, etc.
-
C programs start from the
main()
function and are built using proper syntax rules. -
Use semicolons, follow case sensitivity, and organize your code using functions and blocks.