C uses a standard set of characters:
Letters: A–Z, a–z
Digits: 0–9
Special Symbols: + - * / = < > ; , { } ( ) [ ] # & % etc.
Whitespace: Space, Tab, Newline
2️. Tokens in C
Tokens are the smallest units of a C program. They include:
Token Type Examples
Keywords int, return, if, while, for
Identifiers Variable or function names like age, main
Constants 10, 3.14, 'A', "Hello"
Operators +, -, *, =, ==, &&
Special Symbols ;, {}, (), [], ,
auto break case char const continue default do double
else enum extern float for goto if int long
register return short signed sizeof static struct switch typedef
union unsigned void volatile while
Identifiers:-
In C programming, identifiers are user-defined names used to uniquely identify various program elements. These elements include variables, functions, arrays, structures, unions, and labels.
Rules for Identifiers :-
Identifier names are unique.
Cannot use a keyword as identifiers.
Identifier has to begin with a letter or underscore (_).
It should not contain white space.
Identifiers can consist of only letters, digits, or underscore.
Constants:-
In C programming, constants are fixed values that cannot be altered or changed during the execution of a program. They are also referred to as literals. Constants can be of various data types, including integer, floating-point, character, and string.
For Example :- PI = 3.14159 , INITIAL = 'A' etc .
Every C program has the following structure:
#include <stdio.h> // Preprocessor directive
#include <conio.h>
int main() { // Main function: entry point
printf(" Welcome to IT Tech"); // Statements
getch(); // End of program
}
Basic Syntax Rules
Element Description
Statements End with a semicolon ;
Braces {} Used to group multiple statements (e.g., in functions, loops)
Comments // Single-line, /* Multi-line */
Comments in C :-
Single line comment : Single-line comments begin with two forward slashes (//). All text from the // to the end of the line is treated as a comment.
For example : printf(" Sum = %d",s); // Display the result of addtion
Multi line comment :Multi-line comments begin with a forward slash followed by an asterisk (/*) and end with an asterisk followed by a forward slash (*/). Any text between these delimiters, across multiple lines, is treated as a comment .
For example : printf(" Sum = %d",s); /* Display the result of addtion
printf is output function */
#include directive :-
The #include directive in C is a preprocessor command used to incorporate the contents of a specified file, typically a header file, into the current source code file before compilation . Here '#' is preprocessor directive . Here some examples of the header files .
#include<stdio.h> (Standard Input/Output):
Provides functions for input and output operations, such as printf() for printing to the console and scanf() for reading input.
#include<stdlib.h> (Standard Library):
Contains general utility functions, including memory allocation (malloc(), free()), process control (exit()), string conversions (atoi()), and random number generation (rand()).
#include<string.h> (String Handling):
Offers functions for manipulating strings, such as copying (strcpy()), concatenating (strcat()), comparing (strcmp()), and finding lengths (strlen()).
#include<math.h> (Mathematics):
Includes mathematical functions like sqrt() (square root), sin() (sine), cos() (cosine), pow() (power), and log() (logarithm).
#include<Conio.h> (Console Input/Output):
Includes functions like clrscr() (clearscreen), getch() (getcharacter).
main() :- Every executable C program must have exactly one main() function, as it dictates where the program's execution flow will begin. In C programming, the main() function serves as the entry point for program execution.
Click Here For Input/Output statements
OR
Sections of the C Program or Structure of C program
There are 6 basic sections responsible for the proper execution of a program. Sections are mentioned below:
Documentation
Preprocessor Section
Global Declaration
Main() Function
Sub Programs
1. Documentation
This section consists of the description of the program, the name of the program, and the creation date and time of the program. It is specified at the start of the program in the form of comments. Documentation can be represented as:
// description, name of the program, programmer name, date, time etc.
or
/*
description, name of the program, programmer name, date, time etc.
*/
All the header files of the program will be declared in the preprocessor section of the program. Header files help us to access other's improved code into our code. A copy of these multiple files is inserted into our program before the process of compilation.
Example:
#include<stdio.h>
#include<math.h>
The global declaration section contains global variables, function declaration, and static variables. Variables and functions which are declared in this scope can be used anywhere in the program.
Example:
int num = 18;
Every C program must have a main function. The main() function of the program is written in this section. Operations like declaration and execution are performed inside the curly braces of the main program. The return type of the main() function can be int as well as void too. void() main tells the compiler that the program will not return any value. The int main() tells the compiler that the program will return an integer value.
Example:
void main()
or
int main()
User-defined functions are called in this section of the program. The control of the program is shifted to the called function whenever they are called from the main or outside the main() function. These are specified as per the requirements of the programmer.
Example:
int sum(int x, int y)
{
return x+y;
}