C Language Overview
C is a structured, procedural, and general-purpose programming language developed by
Dennis Ritchie at Bell Laboratories in 1972. It is often called the foundation of modern
programming languages because many languages like C++, Java, and Python are derived
from its syntax and concepts. C is a compiled language, meaning the source code is
converted into machine code by a compiler before execution, which makes it very fast and
efficient. It is widely used in operating systems, embedded systems, and hardware-level
programming.
Basic Structure of a C Program
A C program is divided into several sections such as header files, global declarations,
functions, and the main() function. The execution of every C program starts from the main()
function.
Example:
#include <stdio.h> // header file
int main() {
printf("Hello, World!");
return 0;
#include imports libraries like stdio.h for input/output functions.
printf() is used to display output on the screen.
Every statement in C ends with a semicolon (;).
Data Types, Variables, and Operators
C supports different data types like int, float, char, double, and void. Variables store data
values, and they must be declared before use. Operators are symbols used to perform
operations on variables and values.
Example:
int a = 10, b = 5;
float result = a / (float)b;
printf("Result = %.2f", result);
Common operators include:
Arithmetic: +, -, *, /, %
Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, !
Assignment: =, +=, -=
Control Structures and Loops
C uses decision-making and looping statements to control the flow of execution.
Examples:
if(a > b)
printf("A is greater");
else
printf("B is greater");
for(int i = 1; i <= 5; i++)
printf("%d ", i);
if-else: executes statements conditionally.
switch: selects one case from multiple options.
for, while, and do-while: used for repeating tasks multiple times.
Arrays, Strings, and Functions
Arrays store multiple values of the same data type under one name, while strings are
character arrays ending with a null character (\0). Functions help in dividing code into smaller
reusable blocks.
Example:
int add(int x, int y) {
return x + y;
int main() {
int sum = add(5, 3);
printf("Sum = %d", sum);
return 0;
}
Functions can be user-defined or predefined (like printf(), scanf()). Using functions improves
readability and reusability of code.
Pointers, Structures, and File Handling
Pointers are variables that store memory addresses. They are powerful for memory
management and data manipulation. Structures (struct) group related data of different types,
and file handling allows storing and retrieving data from files.
Example:
struct Student {
char name[20];
int age;
};
struct Student s1 = {"Rahul", 20};
printf("Name: %s, Age: %d", s1.name, s1.age);
Files in C are handled using functions like fopen(), fprintf(), fscanf(), and fclose().
Example:
FILE *f = fopen("data.txt", "w");
fprintf(f, "Hello C Programming!");
fclose(f);
These features make C powerful, efficient, and suitable for system-level programming.