Name: Mahtab Alam Ansari: Supreme Institute of Management and Technology
Name: Mahtab Alam Ansari: Supreme Institute of Management and Technology
Stream :
BCA
Semester :
01
Year : 0 1
CHAPTER-07
“Arrays”
CHAPTER-01
“Overview of C”
Overvie
Introduction
w
History of C
Importance of
C
Sample C
programs
Basic structures of C
programs Programming style
Executing a C program
INTRODUCTION
D ennis Ritchie
Foundation for Other Languages: C influenced and
became
the basis for languages like C++, Java, and many
Importance of
C
Foundation for Other Languages: C is the base for many modern
languages like C++, Java, and Python.
{ } Variable Declaration :
int a, b;
Logic : Statements to
perform operations.
Categories :
Alphabets : A-Z,
a-z. Digits : 0-9.
Special Symbols : $, %, *, @,
etc. White Spaces : Space,
newline, tab.
Exampl char letter =
e: 'A';
C
Tokens
Definition: Smallest individual units in a C
program.
Types :
5, 3.14).
Exampl int num = : Symbols that perform
Operators
e: 5;operations (+, *, =).
Keywords and
Identifiers
Keywords : Reserved words with special meaning
Exampl int
e: age;
Constan
ts
Definition: Fixed values that do not change during
execution.
Types :
Basic Types :
int: Whole numbers.
float: Decimal
numbers. char:
Syntax variable_name =
: value;
Exampl
e: int num =
10; char
letter = 'B';
Defining Symbolic
Constants
Definition : A name that represents a
constant value
Characteristics :
Cannot be modified.
Typically written in uppercase
letters.
Exampl #define PI
e: 3.14159
CHAPTER-03
List of Operators:
Addition [+] Subtraction [-] Multiplication [*] Division [/] Modulus [%]
List of Operators:
Logical
Operators
Definition: These operators are used to combine multiple
conditions.
List of Operators:
Assignment
Definition: TheseOperators
operators assign values to
variables.
Increment and
Decrement Operato
Definition: These operatorsrs
increase or decrease the value of a
variable by 1.
Increment operator Decrement operator
in C in C
Conditional
Operators
Definition: A shorthand for if-else statements, also known as the
ternary operator.
Arithmetic Operators
In C
Bitwise
Operators
Definition: These operators perform bit-level operations on
integers.
Evaluation of
Expressions
Definition: The process by which an expression is simplified or
calculated.
3 + 5 * 2 is evaluated as 3 +
(5 * 2).
Operator Precedence and
Definition: IfAssociativity
two operators have the same precedence, associativity defines
the direction in which the expression is evaluated.
Example: 3 - 2 + 5 is
evaluated from left to right
because - and + are left-
associative
CHAPTER-04
Example
:
c
h
a
r
Explanation: The getchar() function reads one character at a time
from the input buffer. This is useful when you want to capture
c and handle characters individually.
h
;
Writing a
device.
Character
Definition: Writing or displaying a single character to the output
Example
:
#incl
ude
<stdi
o.h>
void
main(
)
{
char ch = 'A';
printf("ch = %c\
n",ch);
Formatted
Input
Definition: Input that is read in a specific data format, like
integers or floating- point numbers.
Examp
l
e
:
int num;
scanf("%d", &num); // Reads an
integer
Explanation: The scanf() function allows value
reading formatted data
from the user.
In this example, % d is used to read an integer. The input is
stored in the variable num.
Formatted
Output
Definition: Outputting data in a specific format to make it
more readable and structured.
Exampl
e
:
int num = 5;
printf("The number is: %d", num); //
Outputs: The number is: 5
IF.....ELSE statements
INTRODUCTIO
N
Decision-making structures control the flow of execution in a
program based on conditions.
Synta Exampl
x: e:
if (condition) {
if (age > 18)
// code to be executed if
{ printf("You are an
condition
adult.");
is true
}
}
Simple IF
Statement
Definition: A simple if statement checks a single
condition.
Synta Exampl
x: e:
if if (x > 10) {
(condition) printf("x is greater
{ than 10.");
// code }
}
The IF ELSE
Statement
Definition: The IF ELSE statement executes one block of code if the
condition is true, and another block if false.
Synta Exampl
x: e:
Synta Exampl
x: e:
if if (x > 0 ) {
(condition1) if (x < 10 0 )
{ if { printf("x is
(condition2) between 1 and
{ 99");
// code if both }
condition1 and }
condition2 are true
The ELSE IF
Ladder
Definition: Multiple conditions are checked using ELSE IF,
where the first true condition's block is
executed.
Synta Exampl
x: e:
if (condition1) { if (score > 90 )
// code if condition1 is { printf("Grad
true e A");
} else if (condition2) { } else if (score >
// code if condition2 is 75)
true { printf("Grad
} else { e B ");
// code if all conditions } else
are false
The Switch
Statement
Definition: The switch statement allows selecting one of many
blocks of code to execute.
Syntax: Example:
switch
switch (day) {
(expression) {
case 1:
case
printf("Monda
constant1:
y");
// code for
brea
case 1
k;
break;
case
case constant2:
2:
// code for
printf("Tuesda
case 2
y");
break;
break;
default:
default:
The ?:
Operator
Definition: Also known as the conditional or ternary operator, it’s a
shorthand for the IF ELSE statement.
Synta Exampl
x: e:
Synta Exampl
x: e:
if (x < 0 )
goto
label; { goto
... error;
label: }
// code to error:
be printf("Err
executed or:
N egative
CHAPTER-06
Introduction
The WHILE
statement The DO
statement The FOR
statement Jumps in
LOOPS
INTRODUCTIO
N
Looping structures allow repeating a set of instructions until a condition
is met.
Synta Exampl
x: e:
int i =
do {
0;
// code to
do {
be
printf("%
executed
d",
} while
i);
(conditio
i+
n);
+;
The FOR
Statement
Definition: The FOR loop repeats a block of code a specific
number of times.
Synta Exampl
x: e:
“Arrays
”
Overvie
w
Introduction
One-dimensional arrays
Two-dimensional arrays
Initializing two-
dimensional arrays
Multidimensional arrays
INTRODUCTIO
N
An array is a collection of variables that are stored in contiguous
memory locations. All elements in an array must be of the same
data type.
Arra
y
Synta Exampl
x: e:
int numbers[5]; //
dataType
Declares an array of
arrayName[arraySize];
5 integers
Syntax: Example:
Syntax: Example:
Syntax: Example:
dataType arrayName[rows][columns]
= {{value1, value2}, {value3, int matrix[2][2] = {{1, 2}, {3,
value4}}; 4}};