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 : 01
CHAPTER-07
“Arrays”
CHAPTER-01
“Overview of C”
Overview
Introduction
History of C
Importance of C
Sample C programs
Basic structures of C programs
Programming style
Executing a C program
INTRODUCTION
Dennis Ritchie
Foundation for Other Languages: C influenced and became
the basis for languages like C++, Java, and many others.
Importance of C
Foundation for Other Languages: C is the base for many modern languages
like C++, Java, and Python.
Meaningful Variable Names: Use descriptive names (e.g., totalMarks instead of t).
Introduction Variables
Character Set in C Data Types
C Tokens Declaration of Variables
Keywords and Identifiers Assigning Values to Variables
Constants Defining Symbolic Constants
INTRODUCTION
Like any other language, C has its own vocabulary and grammar. In this
chapter , we will discuss the concepts of constants and variables and their
types.
Character Set in C
Definition: Character set includes letters, digits, special symbols, and spaces used in C.
Categories :
Types :
Rules :
Types :
Character Constants : ingle characters enclosed in single quotes (e.g., 'A', '5').
Basic Types :
int: Whole numbers.
Example :
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.
List of Operators:
Addition [+] Subtraction [-] Multiplication [*] Division [/] Modulus [%]
#include <stdio.h> #include <stdio.h> #include <stdio.h> #include <stdio.h> #include <stdio.h>
void main() void main() void main() void main() void main()
{ { { { {
int a=2,b=3,sum; int a=5,b=10,sub; int a=5,b=10,mul; int a=5,b=10,div; int a=5,b=10,mod;
sub = a - b; mul = a * b;
sum = a + b; div = a / b; mod = a % b;
printf("The printf("The
printf("The sum of printf("The division printf("The modulus
substraction of %d multiplication of %d
%d and %d is of %d and %d is of %d and %d is
and %d is %d\n", a, and %d is %d\n", a, b,
%d\n", a, b, sum); %d\n", a, b, div); %d\n", a, b, mod);
b, sub); mul);
Relational Operators
Definition: These operators compare two values and return true or false.
List of Operators:
Logical Operators
Definition: These operators are used to combine multiple conditions.
List of Operators:
Assignment Operators
Definition: These operators assign values to variables.
Increment and Decrement
Operators
Definition: These operators increase or decrease the value of a variable by 1.
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 Associativity
Definition: If two operators have the same precedence, associativity defines the direction
in which the expression is evaluated.
Introduction
Reading a Character
Writing a Character
Formatted input
Formatted output
INTRODUCTION
In C programming, input refers to taking data from the user or a file, and
output refers to displaying data to the screen or another device.
Input and output operations are essential for user interaction, debugging,
and file handling.
Reading a Character
Definition: Reading a single character from the user or from a file.
Example:
char ch;
ch = getchar(); // Reads a character from the user
Explanation: The getchar() function reads one character at a time from the input
buffer. This is useful when you want to capture and handle characters
individually.
Writing a Character
Definition: Writing or displaying a single character to the output device.
Example:
#include <stdio.h>
void main()
{
char ch = 'A';
printf("ch = %c\n",ch);
printf("ch = %d, hence an integer\n",ch);
}
Example:
int num;
scanf("%d", &num); // Reads an integer value
Explanation: The scanf() function allows 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.
Example:
int num = 5;
printf("The number is: %d", num); // Outputs: The
number is: 5
Explanation: The scanf() function allows reading formatted data from the user.
In this example, %d is used to read an integer. The input is stored in the variable
num.
CHAPTER-05
Syntax: Example:
if (condition) {
if (age > 18) {
// code to be executed if condition
printf("You are an adult.");
is true
}
}
Simple IF Statement
Definition: A simple if statement checks a single condition.
Syntax: Example:
Syntax: Example:
Syntax: Example:
if (condition1) { if (x > 0) {
if (condition2) { if (x < 100) {
// code if both condition1 and printf("x is between 1 and
condition2 are true 99");
} }
} }
The ELSE IF Ladder
Definition: Multiple conditions are checked using ELSE IF, where the first true
condition's block is executed.
Syntax: Example:
switch (expression) {
switch (day) {
case constant1:
case 1:
// code for case 1
printf("Monday");
break;
break;
case constant2:
case 2:
// code for case 2
printf("Tuesday");
break;
break;
default:
default:
// code if none of the
printf("Invalid day");
cases match
}
}
The ?: Operator
Definition: Also known as the conditional or ternary operator, it’s a shorthand for
the IF ELSE statement.
Syntax: Example:
Syntax: Example:
if (x < 0) {
goto label;
goto error;
...
}
label:
error:
// code to be
printf("Error:
executed
Negative number");
CHAPTER-06
Introduction
The WHILE statement
The DO statement
The FOR statement
Jumps in LOOPS
INTRODUCTION
Syntax: Example:
int i = 0;
do {
do {
// code to be
printf("%d",
executed
i);
} while
i++;
(condition);
} while (i < 5);
The FOR Statement
Definition: The FOR loop repeats a block of code a specific number of times.
Syntax: Example:
“Arrays”
Overview
Introduction
One-dimensional arrays
Two-dimensional arrays
Initializing two-dimensional
arrays
Multidimensional arrays
INTRODUCTION
Syntax: Example:
Explanation: Arrays allow you to store multiple values of the same type, which can
be accessed by their index.
One-Dimensional Arrays
Definition: A one-dimensional array is a list of elements of the same type.
Syntax: Example:
Syntax: Example:
Syntax: Example:
Syntax: Example:
dataType arrayName[rows][columns]
= {{value1, value2}, {value3, value4}}; int matrix[2][2] = {{1, 2}, {3, 4}};
URL :- https://www.geeksforgeeks.org/c-programming-language/