C Programming Language
C is a general-purpose mid-level programming language developed by Dennis M. Ritchie
at Bell Laboratories in 1972. It was initially used for the development of UNIX operating
system, but it later became popular for a wide range of applications. Today, C remains
one of the top three most widely used programming languages.
Why Learn C?
• C is considered mother of all programming languages as many later languages
like Java, PHP and JavaScript have borrowed syntax/features directly or indirectly
from the C.
• If a person learns C programming first, it helps to learn any modern programming
language as it provide a deeper understanding of the fundamentals of
programming and underlying architecture of the operating system like pointers,
working with memory locations etc.
• C is widely used in operating systems, embedded systems, compilers,
databases, networking, game engines, and real-time systems for its efficiency to
work in low resource environment and hardware-level support.
Writing First Program in C Language
This simple program demonstrates the basic structure of a C program. It will also help
us understand the basic syntax of a C program.
#include <stdio.h>
int main(void)
// This prints "Hello World"
printf("Hello World");
return 0;
Output Hello World
Applications of C
1. Operating Systems (like Windows or Linux)
You know how your computer or phone runs an operating system?
C is used to create those operating systems.
In fact, Linux and parts of Windows are written in C.
2. Electronics and Gadgets (Embedded Systems)
C is used inside machines and smart devices — like:
Washing machines, Smart TVs, Remote controls, Cars (for automatic controls)
These devices have small computers inside, and C tells them what to do.
3. Games
Games that need to run fast often use C.
It helps handle graphics, sound, and speed without slowing down.
Some parts of big games and game engines are built using C.
4. Normal Software (Desktop Apps)
Software like text editors, calculators, and even some parts of Photoshop are made
using C.
It helps create software that runs quickly and doesn’t use too much memory.
5. Networking (Internet and Communication)
C helps in building software that runs:
Internet connections, Routers, Servers
So, if you’re using Wi-Fi or browsing the web, chances are C is working behind the
scenes.
Data Types in C
Each variable in C has an associated data type. It specifies the type of data that the
variable can store like integer, character, floating, double, etc.
Example:
int number;
The above statement declares a variable with name number that can
store integer values.
The data types in C can be classified as follows:
Basic Data Types (Yellow section)
These are the fundamental types used for storing simple values like numbers and
characters.
Integer Data Type
The integer datatype in C is used to store the integer numbers (any number including
positive, negative and zero without decimal part). Octal values, hexadecimal values,
and decimal values can also be stored in int data type in C.
• Size: 4 bytes
• Format Specifier: %d
Format specifiers are the symbols that are used for printing and scanning values of
given data types.
Example:
We use int keyword to declare the integer variable:
int val;
We can store the integer values (literals) in this variable.
#include <stdio.h>
int main() {
int var = 22;
printf("var = %d", var);
return 0;
}
Output
var = 22
A variable of given data type can only contains the values of the same type. So, var can
only store numbers, not text or anything else.
Character Data Type
Character data type allows its variable to store only a single character. The size of the
character is 1 byte. It is the most basic data type in C. It stores a single character and
requires a single byte of memory in almost all compilers.
• Range: (-128 to 127) or (0 to 255)
• Size: 1 byte
• Format Specifier: %c
Example:
#include <stdio.h>
int main() {
char ch = 'A';
printf("ch = %c", ch);
return 0;
Output
ch = A
Float Data Type
In C programming, float data type is used to store single precision floating-point
values. These values are decimal and exponential numbers.
• Size: 4 bytes
• Format Specifier: %f
Example:
#include <stdio.h>
int main() {
float val = 12.45;
printf("val = %f", val);
return 0;
Output
val = 12.450000
Double Data Type
The double data type in C is used to store decimal numbers (numbers with floating
point values) with double precision. It can easily accommodate about 16 to 17 digits
after or before a decimal point.
• Size: 8 bytes
• Format Specifier: %lf
Example:
#include <stdio.h>
int main() {
double val = 1.4521;
printf("val = %lf", val);
return 0;
Output
val = 1.452100
Void Data Type
The void data type in C is used to indicate the absence of a value. Variables of void data
type are not allowed. It can only be used for pointers and function return type and
parameters.
Example:
void fun(int a, int b){
// function body
where function fun is a void type of function means it doesn't return any value.
Size of Data Types in C
The size of the data types in C is dependent on the size of the architecture, so we cannot
define the universal size of the data types. For that, the C language provides
the sizeof() operator to check the size of the data types.
Example
#include <stdio.h>
int main(){
// Use sizeof() to know size
// the data types
printf("The size of int: %d\n",
sizeof(int));
printf("The size of char: %d\n",
sizeof(char));
printf("The size of float: %d\n",
sizeof(float));
printf("The size of double: %d",
sizeof(double));
return 0;
Output
The size of int: 4
The size of char: 1
The size of float: 4
The size of double: 8
Derived Data Types (Blue section)
These are based on basic types and used for more complex data structures.
These are smart tools that hold multiple values or manage how data is used in memory.
array Collection of similar data types (like a list)
pointer Stores the address of another variable
function Block of code that performs a specific task
Example
int arr[5] = {1, 2, 3, 4, 5}; // array
int *ptr = &arr[0]; // pointer
User Defined Data Types (Pink section)
These are custom data types that you create yourself — using combinations of
basic or derived types.
Type Description
struct Combines different data types into one
union Like struct, but shares memory space
enum Lets you name a group of constants
These are like creating your own data boxes for organizing more complex info — like
a student profile with name, roll number, and marks.
Example:
struct student {
int roll;
char name[20];
float marks;
};
C Variables
A variable in C is a named piece of memory which is used to store data and access it
whenever required. It allows us to use the memory without having to memorize the
exact memory address.
Syntax for Creating Variables
To create a variable in C, we have to specify a name and the type of data it is going to
store in the syntax.
data_type name;
C provides a set of different data types that can store almost all kinds of data. For
example
int num;
char letter;
float decimal;
The above statements are called variable declarations. In C, every variable must be
declared before it is used. We can also declare multiple variables of same data type in a
single statement by separating them using comma as shown:
data_type name1, name2, name3, ...;
Rules for Naming Variables in C
We can assign any name to a C variable as long as it follows the following rules:
• A variable name must only contain letters, digits, and underscores.
• It must start with an alphabet or an underscore only. It cannot start with a digit.
• No white space is allowed within the variable name.
• A variable name must not be any reserved word or keyword.
• The name must be unique in the program.
• It is a case-sentive ex; top and Top both are diffrent
Constants in C
In C programming, const is a keyword used to declare a variable as constant, meaning
its value cannot be changed after it is initialized. It is mainly used to protect variables
from being accidentally modified, making the program safer and easier to understand.
These constants can be of various types, such as integer, floating-point, string, or
character constants.
Syntax
const data_type var_name = value;
example:
#include <stdio.h>
int main() {
const int a = 10;
printf("%d", a);
return 0;
Output
10
Constants Using #define
In C, the #define directive can also be used to define symbolic constants that do not
require a data type. They are called macros and are replaced by their values at compile
time.
Syntax:
#define CONSTANT_NAME value
Example:
#include <stdio.h>
#define PI 3.14
int main() {
printf("%.2f", PI);
return 0;
Output
3.14
C Identifiers
In C programming, identifiers are the names used to identify variables, functions,
arrays, structures, or any other user-defined items. It is a name that uniquely identifies a
program element and can be used to refer to it later in the program.
Example:
int val = 10;
void func() {}
In the above code snippet, "val" and "func" are identifiers.
Rules for Naming Identifiers in C
A programmer must follow a set of rules to create an identifier in C:
• Identifier can contain following characters:
o Uppercase (A-Z) and lowercase (a-z) alphabets.
o Numeric digits (0-9).
o Underscore (_).
• The first character of an identifier must be a letter or an underscore.
• Identifiers are case-sensitive.
• Identifiers cannot be keywords in C (such as int, return, if, while etc.).
The below image and table show some valid and invalid identifiers in C language.
Creating an Identifier for a Variable
#include <stdio.h>
int main() {
int var;
var = 10;
printf("%d", var);
return 0;
Output
10
Creating an Identifier for a Function
#include <stdio.h>
int sum(int a, int b) {
return a + b;
int main() {
printf("%d", sum(10, 20));
return 0;
Output
30
5. Input and Output
printf() → used to print output.
printf() – Output Function
Used to print/display messages, numbers, variables.
int age = 20;
printf("My age is %d", age);
Output: My age is 20
scanf() → used to take input from the user.
scanf() – Input Function
Used to take user input.
int age;
scanf("%d", &age);
%d → for int, %f → for float, %c → for char, %s → for string
&age means “store input in variable age”