1
Beng 1 - CSE & DAE
TP
2
TABLE OF CONTENTS
1. Introduction to C
2. History of C
3. Features of C
4. Structure of a C Program
5. Basic Syntax
6. Data Types, Variables, and Operators
7. Control Statements
8. Applications of C
9. Conclusion
3
INTRODUCTION
TO C
What is C
programming?
Definition: C is a high-level,
general-purpose programming
language that provides low-
level access to memory and
system processes.
Designed for system
programming, it is widely used
for developing operating
systems.
4
HISTORY OF
C
Origin: Developed by Dennis
Ritchie at Bell Labs in 1972.
Influences: Based on the B
programming language.
Evolution:
• K&R C: The original version described
in "The C Programming Language"
book by Kernighan and Ritchie.
• ANSI C: Standardized version by ANSI
in 1989.
• ISO C: Further standardized by ISO in
1990.
5
FEATURES
OF C
Simplicity: Simple syntax
and easy to learn.
Efficiency: Produces
highly efficient programs.
Portability: Code can run
on different machines with
little or no modification.
Rich Library: Provides a
rich set of built-in functions.
6
7
STRUCTURE OF C
Header Files: Include
necessary libraries (e.g., Statements and
#include <stdio.h>). Expressions:
Main Function: Entry
Perform operations
and control program
point of the program (int
main()). flow.
Return Functions:
Variable
Define reusable code
Declarations: Declare
blocks.
variables to store data
8
#include <stdio.h> //
Preprocessor directive BASIC SYNTAX
Preprocessor Directive:
// Function declaration
int main() { #include <stdio.h>: This line
// Variable declaration includes the Standard Input
int a; Output library, which allows the
// Initialization use of functions like printf.
a = 10;
Function Declaration:
// Function call int main() : This line declares
printf("Value of a is %d\
the main function, which is the
n", a);
entry point of any C program.
// Return statement Variable Declaration:
return 0;
int a; : This line declares an
}
integer variable a.
9
#include <stdio.h> //
Preprocessor directive
BASIC SYNTAX
Initialization::
// Function declaration
int main() { a = 10;: This line initializes the
// Variable declaration variable a with the value 10.
int a;
Return Statement:
// Initialization
a = 10; return 0;: This line returns 0,
indicating that the program
// Function call has been executed
printf("Value of a is %d\
successfully.
n", a);
Closing Bracket:
// Return statement }: This line marks the end of
return 0;
the main function.
}
10
DATA TYPES, VARIABLES, AND
OPERATORS
Data Types Variables
int: Integer • int age;
float: Floating-point • float salary;
number • char initial;
double: Double-
precision floating-
point number
char: Character
11
Operators
Arithmetic Operators: +,
-, *, /, %
Relational Operators:
==, !=, >, <, >=, <=
Logical Operators: &&, ||,
!
Assignment Operators:
=, +=, -=, *=, /=, %=
Increment/Decrement
Operators: ++, --
12
CONTROL STATEMENTS
If Statement: If-Else Statement:
if (condition) { if (condition) {
// code // code
} else {
}
MARGIE'S TRAVEL
// code
}
The if statement The if-else statement
executes a block of executes one block of
code if a specified code if the condition is
condition is true. true, and another block
if the condition is false.
13
CONTROL STATEMENTS
Switch Statement: The switch
switch (variable) { statement executes
case value1: one of many blocks
// code
of code based on the
value of a variable.
break;
case value2:
// code
break;
default:
// code
}
14
CONTROL STATEMENTS
For Loop: While loop:
for (initialization; while (condition) {
condition; increment) { // code
// code }
} The while loop
The for loop repeats repeats a block of
a block of code a code as long as a
specific number of specified condition is
times. true.
15
CONTROL STATEMENTS
Do-while loop:
The do-while
loop is similar
to the while DO {
loop, but it
// CODE TO BE
exe c u t e s t h e
block of code EXECUTED
at least once } WHILE
b e f o re (CONDITION);
checking the
condition.
16
APPLICATIONS
OF C
Operating Systems: Unix,
Linux, Windows
Compilers: GCC, Clang
Embedded Systems:
Microcontrollers, IoT devices
Game Development:
Game engines, graphics
programming
Database Systems:
MySQL, Oracle
17
CONCLUSION
Summary: C programming is a foundational
language that offers simplicity, efficiency, and
flexibility, making it suitable for a wide range of
applications.