Introduction to Subject
PICT, Pune. Mrs. Madhuri S. Patil
Outcome Based Education
And
Basic Concepts in Computer
Science
PICT, Pune. Mrs. Madhuri S. Patil
Objective and Outcome:
Objective:
The Objective of Outcome-Based Education is to design and structure education in a way that ensures
students achieve predetermined learning outcomes. It emphasizes equipping students with the knowledge, skills,
and attitudes necessary for real-world success, promoting.( Clarity, Consistency, Student empowerment)
Outcomes:
Students will be able to,
● Explain key concepts
● Apply critical thinking and problem-solving techniques to real-world situations.
● Collaborate and work effectively in diverse, multicultural teams.
● Demonstrate ethical behavior and social responsibility in their professional practice.
● Adapt to new challenges and continuous learning in their careers.
PICT, Pune. Mrs. Madhuri S. Patil
What is Outcome Based Education?
● Outcome-based education is a system where all the parts and aspects of education are focused on the
outcomes of the course. The students take up courses with a certain goal of developing skills or
gaining knowledge and they have to complete the goal by end of the course.
● There is no specific style or time limit of learning. The student can learn as per their choice. The
faculty members, moderators, and instructors guide the students based on the target outcomes.
PICT, Pune. Mrs. Madhuri S. Patil
Topics to be covered:
● Prerequisites in Computer Architecture
● Machine Cycle
● Memory
● Coding Languages
● Time-Space Complexity
PICT, Pune. Mrs. Madhuri S. Patil
Introduction to Outcome-Based Education (OBE):
● Outcome-Based Education (OBE) focuses on achieving specific learning outcomes
● Objective: Students will be able to apply the principles of OBE to create and assess learning activities that focus on achieving
specific outcomes in computer science.
● Key Principles:
○ Clarity of focus on outcomes.
○ Designing curriculum backward from the desired outcomes.
○ High expectations for all learners.
○ Continuous assessment and improvement.
PICT, Pune. Mrs. Madhuri S. Patil
Importance of Prerequisites in OBE:
Context: Prerequisites are foundational knowledge necessary for advanced learning.
Relevance in Computer Science: Understanding computer architecture, programming, and complexity is essential for grasping higher-
level concepts.
PICT, Pune. Mrs. Madhuri S. Patil
Computer Architecture Foundations:
Definition: Study of the structure, organization,
and operation of computer systems.
Key Components:
● Central Processing Unit (CPU)
● Memory Hierarchy (RAM, Cache, Registers)
● Input/Output Devices
● Storage Systems
PICT, Pune. Mrs. Madhuri S. Patil
Machine Cycle in Computing:
Definition: The basic operation cycle of a computer.
Stages of the Machine Cycle:
● Fetch: Retrieve instruction from memory.
● Decode: Translate instruction into commands.
● Execute: Perform the command.
● Store: Write results back to memory.
Importance: Understanding the machine cycle is crucial for optimizing performance and understanding computer
operations.
PICT, Pune. Mrs. Madhuri S. Patil
Types of Memory in Computer Systems:
PICT, Pune. Mrs. Madhuri S. Patil
PICT, Pune. Mrs. Madhuri S. Patil
What is Program:
● A program is a sequence of instructions that can be executed by a
computer to solve some problem or perform a specified task.
● A programming language is an artificial language designed
to automate the task of organizing and manipulating information, and
to express problem solutions precisely
Programing Language
Structural Object Oriented
C, Fortran, Pascal, Cobol, Basic JAVA, C++, C#
PICT, Pune. Mrs. Madhuri S. Patil
Low-Level vs. High-Level Programming Languages:
0s and 1s ADD, MOV
PICT, Pune. Mrs. Madhuri S. Patil
The Evolution of High-Level and Low-Level Languages
PICT, Pune. Mrs. Madhuri S. Patil
Time and Space Complexity:
● Time Complexity: Measure of the amount of time an algorithm takes to complete as a function of
the input size.
○ Analyze Loops, Recursive Algorithms
● Space Complexity: Measure of the amount of memory an algorithm uses as a function of the
input size.
PICT, Pune. Mrs. Madhuri S. Patil
Applying OBE in Computer Science Education:
● Outcome Identification: Define specific skills and knowledge that students should acquire.
● Curriculum Design: Develop learning activities that align with desired outcomes.
● Assessment: Measure learning outcomes using various assessment techniques.
PICT, Pune. Mrs. Madhuri S. Patil
Introduction
Module-I
PICT, Pune. Mrs. Madhuri S. Patil
Content:
● Problem solving in everyday life
● Types of problem: Algorithmic & Heuristic
● Problem solving with Computer
● Algorithms and Flowcharts.
● Introduction to “C” Programming: data types, constants, keywords, variables, operators, and
expressions, input/output statements, Notion of Assembler, Interpreter and Compiler.
PICT, Pune. Mrs. Madhuri S. Patil
Objective:
By the end of this lecture, students will be able to:
● Define who an engineer.
● Apply engineering thinking.
● Recognize problem-solving in everyday life.
● Solve computational problems using engineering principles.
● Explain the concept of computational thinking.
● Generate and test algorithms and flowchart.
PICT, Pune. Mrs. Madhuri S. Patil
Who is an engineer?
“Engineers are people who solve problems – they invent, design,
analyze, build and test “things” to fulfill objectives and requirements.”
PICT, Pune. Mrs. Madhuri S. Patil
Think like an engineer
Thinking like an engineer is about creatively finding a solution to some problem.
[Link]
PICT, Pune. Mrs. Madhuri S. Patil
Problem solving in everyday life
Problem-solving in everyday life is a crucial skill that helps us navigate challenges, make decisions, and
improve our well-being (applying logical thinking and creativity to overcome challenges).
1. Identify the Problem
2. Gather Information
3. Generate Possible Solutions
4. Evaluate the Options
5. Choose a Solution
6. Evaluate the Results
PICT, Pune. Mrs. Madhuri S. Patil
Problems:
1. Well-defined Problems(mathematical equation)
2. Ill-defined Problems(Designing a new app)
3. Routine Problems(daily tasks)
4. Non-routine Problems(Handling an unexpected crisis)
5. Simple Problems(checking number is positive or negative)
6. Complex Problems(many tasks and tight deadline)
7. Structured Problems(can solved with algorithms)
8. Unstructured Problems(Predicting stock market)
PICT, Pune. Mrs. Madhuri S. Patil
Question?
Write about a process in your life (e.g. driving to the mall, walking to class, etc.) and
estimate the number of steps necessary to complete the task. Would you consider this
a complex or simple task? What happens if you scale that task (e.g. driving two states
away to the mall)? Is your method the most efficient? Can you come up with a more
efficient way?
1. Doing Laundry
2. Grocery Shopping
3. Cleaning a Room
4. Walking to Class
PICT, Pune. Mrs. Madhuri S. Patil
Types of problem: Algorithmic & Heuristic
Algorithmic Approaches: Algorithmic problems are those that can be solved using a well-defined, step-by-step
procedure or algorithm.
Characteristics of Algorithmic Problems:
1. Definitive Steps
2. Predictable Outcome
3. Clear Problem Definition
4. Efficiency Measurable
PICT, Pune. Mrs. Madhuri S. Patil
Examples:
● Sorting an array (e.g., using quicksort or mergesort).
[Link]
[Link]
[Link]
● Searching for an element in a list (e.g., binary search).
[Link]
● Finding the shortest path in a graph (e.g., Dijkstra's algorithm).
[Link]
PICT, Pune. Mrs. Madhuri S. Patil
Heuristic Problem:
Heuristic Approaches: Heuristic problems are more complex and cannot be solved by a straightforward
algorithmic approach. These problems often require experimentation.( best guess)
Characteristics of Heuristic Problems:
1. No Guaranteed Solution
2. Problem Complexity
3. Trial and Error
4. Subjectivity
Examples:
● Designing a user-friendly interface.
● Optimizing resource allocation in complex projects.
● Developing a strategy for a game with many possible moves (e.g., chess).
PICT, Pune. Mrs. Madhuri S. Patil
Example:
PICT, Pune. Mrs. Madhuri S. Patil
Problem solving with Computer:
● Using computational tools and techniques to analyze, understand, and solve problems.
● Systematic approach to breaking down problems.
1. Understand the Problem
2. Plan the Solution(Algorithmic Design)
3. Execute the plan(Implementation)
4. Testing And Debugging
5. Optimization
6. Documentation and Maintenance
PICT, Pune. Mrs. Madhuri S. Patil
Benefits of Problem Solving with Computers:
● Efficiency
● Automation
● Scalability
● Precision
Problem-solving with computers is a powerful approach that, when combined with the right algorithms and
tools, can solve a wide range of problems efficiently and effectively.
PICT, Pune. Mrs. Madhuri S. Patil
Algorithms and Flowcharts:
Algorithms and flowcharts are essential tools in problem-solving, especially in programming and systems
design.
● Algorithms:
Step-by-step procedure or a set of rules designed to perform task
Logical blueprint of a solution.
Characteristics of Algorithms:
❏ Finiteness: The algorithm must have a finite number of steps.
❏ Definiteness: Each step of the algorithm must be clear and unambiguous.
❏ Input: The algorithm may have zero or more inputs.
❏ Output: The algorithm must produce at least one output.
❏ Effectiveness: Each step of the algorithm must be basic enough to be carried out (computable).
PICT, Pune. Mrs. Madhuri S. Patil
Example:
Problem: Get ready for work or school in the morning.
Steps:
1. Wake up at the alarm.
2. Turn off the alarm.
3. Brush teeth.
4. Take a shower.
5. Get dressed.
6. Prepare breakfast.
7. Eat breakfast.
8. Gather necessary items (e.g., keys, wallet, phone, etc.).
9. Leave the house.
PICT, Pune. Mrs. Madhuri S. Patil
Practice Problem:
● Cooking a Meal Algorithm
● Laundry Algorithm
● Paying a Bill Online Algorithm
● Driving to Work Algorithm
PICT, Pune. Mrs. Madhuri S. Patil
Example(Computational problem):
Algorithm for Addition of Two Numbers
Steps:
1. Start.
2. Input the first number (let's call it num1).
3. Input the second number (let's call it num2).
4. Calculate the sum by adding num1 and num2.
5. Store the result in a variable called sum.
6. Display the result (the value of sum).
7. End.
PICT, Pune. Mrs. Madhuri S. Patil
Question?
1. Write an algorithm to find largest number in the list.
2. Write an algorithm to find the average of 25 test grades out of a possible 100 points.
3. Write an algorithm which repeatedly accepts numbers until the user enters “done”. Once “done” is entered,
display the total sum of all the numbers, the count of numbers entered, and the average of all the numbers.
4. Write an algorithm that sums a series of ten positive integers entered by the user excluding all numbers
greater than 100. Display the final sum.
5. Given five cards randomly placed in a row like the ones below, write an algorithm to sort the cards. How
would your algorithm change if there were 10 cards? What about 100 cards?
PICT, Pune. Mrs. Madhuri S. Patil
Flowcharts:
A flowchart is a graphical representation of an algorithm or a process, showing the
sequence of steps using various symbols.
PICT, Pune. Mrs. Madhuri S. Patil
Example:
PICT, Pune. Mrs. Madhuri S. Patil
Examples for practice:
● Turn a Light On/Off
● Calculate the Area of a Circle
● Student Grade Classification
● Find the Largest of Three Numbers
● Check if a Number is Even or Odd
● ATM Withdrawal Process
PICT, Pune. Mrs. Madhuri S. Patil
Pseudocode:
pseudocode is a simple and concise sequence of English-like instructions to solve a problem.
//Declare variables num1, num2, and sum
1. Initialize num1
2. Initialize num2
3. Initialize sum
// Read values for num1 and num2
4. read num1
5. read num2
// Calculate the sum of num1 and num2
6. sum = num1 + num2
// Display the sum
7. print sum
PICT, Pune. Mrs. Madhuri S. Patil
What is C?
C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph),
located in the U.S.A.
Major parts of popular operating systems like Windows, UNIX, Linux is still written in C
PICT, Pune. Mrs. Madhuri S. Patil
PICT, Pune. Mrs. Madhuri S. Patil
Literals/
Tokens
PICT, Pune. Mrs. Madhuri S. Patil
Language:
Language is a system of communication.
I am Madhu Every language
has grammar
associated with
it.
Am Madhu I
PICT, Pune. Mrs. Madhuri S. Patil
PICT, Pune. Mrs. Madhuri S. Patil
PICT, Pune. Mrs. Madhuri S. Patil
Data Types:
A data type defines the type of data that a variable can hold, specify the size and layout of
the variable’s memory
Categories of Data Types in C:
● Basic (Primary) Data Types
● Derived Data Types
● User Defined
PICT, Pune. Mrs. Madhuri S. Patil
Variables:
Variable is the name of a memory location which stores some data.
PICT, Pune. Mrs. Madhuri S. Patil
Variables Rules:
a. Variables are case sensitive
b. 1st character is alphabet or '_'
c. no comma/blank space
d. No other symbol other than '_'
e. Name should not start with digit
f. Keyword should not be used as variable name
PICT, Pune. Mrs. Madhuri S. Patil
Variables and Data Types:
A data type defines the type of data that a variable can hold, such as integers, floating-point
numbers, characters, etc.
What is Variable:
A variable is a named storage location in memory that is used to hold a value that can be
modified during the execution of a program.
Syntax:
data_type variable_name;
Ex:
int age; int age = 25;
float salary; float salary = 5000.50;
PICT, Pune.
char grade; char grade = 'A'; Mrs. Madhuri S. Patil
Variables Data Types(Memory Space):
Type Size in Memory Description
byte 1 byte Stores whole numbers from -128 to 127
int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647
float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits
boolean 1 bit Stores true or false values
char 2 bytes Stores a single character/letter or ASCII values
PICT, Pune. Mrs. Madhuri S. Patil
Reserved words that have special meaning to the compiler 32 Keywords in C
PICT, Pune. Mrs. Madhuri S. Patil
Keyword void:
1. void is a keyword that indicates "no type" or "nothing”.
2. When a function doesn’t return a value, you declare its return type as void
Example:
void sayHello() {
printf("Hello, World!\n");
}
PICT, Pune. Mrs. Madhuri S. Patil
What is ASCII Value of a Character in C
American Standard Code for Information Interchange (ASCII) is a character encoding standard that
assigns a unique numerical value to all characters including special symbols.
● Each character or special character is represented by some ASCII code.
● Each ASCII code occupies 7 bits in memory.
● Each character variable is assigned an ASCII value ranging from 0 to 127.
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
char ch; // Declare a
character variable
printf("Enter a character: ");
scanf("%c", &ch); // Read a character from the user
printf("The ASCII value of '%c' is: %d\n", ch, ch); // Print the character and its ASCII value
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
Constants:
Values that don't change(fixed)
A constant is a name given to the variable whose values can't be altered or changed.
Using const Keyword Using #define preprocessor
const data_type var_name = value; #define <VAR_NAME> <VALUE>
Const int var=5; #define PI=3.14
statement Preprocessor
Allocate memory area Does Not allocate memory area
Types
Integer Constants
Character Constants
1,2,3,0,-1,-2
’b’’a’,’A’,’#’,’&’
Real Constants
PICT, Pune. 1.0, 2.0, 3.14,-24 Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
#define PI 3.14159 // Preprocessor
directive
int main() {
const int radius = 5; // Constant
printf("Area of circle: %.2f\n", PI * radius * radius);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
Simple C Program Example:
#include <stdio.h>
int main()
{
printf("Welcome to the CPPS lecture, dear students!\n");
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
single-line (//) and multi-line (/* ... */) comments
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h> // Include the standard input-
output library
// Main function where the program execution begins
int main() {
// Print "Hello, World!" to the console
printf("Hello, World!\n");
// Return 0 to indicate that the program ended successfully
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
PICT, Pune. Mrs. Madhuri S. Patil
Coding Technologies(languages)
●
While Coding (programming) there are few important aspects
to remember:
− Syntax:
●
It is about a method or rules of writing coding sentence.
●
Coding sentence can be of one line or multiple lines
− Semantics(Logic):
●
It is about engineering meaning of the coding sentences
●
It is also called as logical sequence of coding or simply; logic
− Errors:
●
These are Syntax mistakes or Semantic mistakes
PICT, Pune. Mrs. Madhuri S. Patil
Types of Errors:
Syntax Errors: violating the syntax rules.
Semantic (Logic) Errors: incorrect meaning or behavior.
Runtime Errors: during the execution of a program(invalid operations)(e.g.,
dividing by zero, accessing invalid memory).
Compile-time Errors: during the compilation process, like syntax errors.
Linker Errors: linking object files during the build process.
PICT, Pune. Mrs. Madhuri S. Patil
Preprocessor directive:
#include <stdio.h> is a preprocessor directive in C programming that tells the compiler to
include the contents of the stdio.h header file in the program before compilation.
Preprocessors are programs that process the source code before compilation.
PICT, Pune. Mrs. Madhuri S. Patil
input/output (I/O) statements:
● Used to interact with the user and the system by taking input from the user
and displaying output to the screen.
● functions provided in header file <stdio.h> which handel I/O statement.
PICT, Pune. Mrs. Madhuri S. Patil
Types of Input Output functions and format Specifier:
PICT, Pune. Mrs. Madhuri S. Patil
input/output (I/O) statements:
printf()
The printf() function is used to print formatted output to the console.
printf("format string", arguments);
printf("I am %d years old.\n", age);
scanf()
The scanf() function reads formatted input from the console. It allows you to read various data
types and store them in variables.
scanf(“format string”,address of variable);
printf("Enter your age: ");
scanf("%d", &age);
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
char name;
int age;
printf("enter your first letter of name:");
scanf("%c",&name);
printf("enter your age:");
scanf("%d",&age);
printf("Name: %c\n", name);
printf("Age: %d\n", age);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
getchar()
The getchar() function reads a single character from the standard input
(keyboard).
char ch;
printf("Enter a character: ");
ch = getchar();
putchar()
The putchar() function prints a single character to the console
putchar('A');
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
ch = getchar(); // Read a character from the
user
printf("You entered: ");
putchar(ch); // Print the
character entered by the user
printf("\n");
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
gets()
The gets() function reads a line of text from the input until a newline character is encountered.
Note: gets() is unsafe and has been deprecated due to buffer overflow risks. It is recommended
to use fgets() instead.
char name[50];
printf("Enter your name: ");
gets(name); // Reads a string from input and stores
it in name
puts()
The puts() function prints a string followed by a newline character. It is simpler but less flexible
than printf().
puts("Hello, World!"); // Output: Hello, World!
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
puts("Hello, World!"); // Print a string literal
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
Operators:
Operators are symbols used to perform operations on variables and values(operands)
PICT, Pune. [Link] Mrs. Madhuri S. Patil
PICT, Pune. Mrs. Madhuri S. Patil
1. Arithmetic Operators:
These operators perform basic mathematical operations:
● Addition (+): Adds two operands.
○ int sum = 5 + 3; // sum = 8
● Subtraction (-): Subtracts the second operand from the first.
○ int difference = 5 - 3; // difference = 2
● Multiplication (*): Multiplies two operands.
○ int product = 5 * 3; //product = 15
● Division (/): Divides the first operand by the second.
○ int quotient = 15 / 3; // quotient = 5
● Modulus (%): Returns the remainder of the division of two operands.
○ int remainder = 15 % 4; // remainder = 3
PICT, Pune. Mrs. Madhuri S. Patil
Arithmetic Instructions
Operator Precedence
*, /, % x = 4 + 9 * 10 Associativity (for same precedence)
+, - Left to Right
= x = 4 * 3x/ =6 4* *2 3 / 6 * 2
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a = 5;
int b = 3;
int sum;
sum= a + b;
printf("Sum: %d\n", sum);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
Questions?
1. Add parenthesis to the expression 6 * 1 - 2 to change its value from 4 to -6.
2. What is the value of variables num1 and num2 after the following C statements are executed?
num = 0
new = 5
num1 = num + new * 2
num2 = num + new * 2
3. A number, a, is a power of b if it is divisible by b and a/b is a power of b. Write a function called pow that takes
parameters a and b and returns True if a is a power of b. Note: you will have to think about the base case.
4. Consider the arithmetic expression 9 - 3 * 2 + 4 / 2.
● Add parentheses to this expression to change its result from 10 to 6.
5. Calculate the values of result1 and result2 after these statements are executed.
int a = 8;
int b = 3;
int c = 4;
int result1 = a % b + c * 2;
int result2 = (a + b) / c - 1;
PICT, Pune. Mrs. Madhuri S. Patil
2. Relational Operators
These operators compare two values and return a boolean result:
● Equal to (==): Checks if two operands are equal.
○ int result = (5 == 3); // result = 0 (false)
● Not equal to (!=): Checks if two operands are not equal.
○ int result = (5 != 3); // result = 1 (true)
● Greater than (>): Checks if the first operand is greater than the second.
○ int result = (5 > 3); // result = 1 (true)
● Less than (<): Checks if the first operand is less than the second.
○ int result = (5 < 3); // result = 0 (false)
● Greater than or equal to (>=): Checks if the first operand is greater than or equal to
the second.
○ int result = (5 >= 3); // result = 1 (true)
● Less than or equal to (<=): Checks if the first operand is less than or equal to the
second.
PICT, Pune. ○ int result = (5 <= 3); // result = 0 (false) Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a = 5;
int b = 7;
int result1=(a==b);
int result2=(a<b);
printf(“result1 is%d”,result1);
printf(“result2 is%d”,result2);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
3. Logical Operators
These operators are used to perform logical operations:
● Logical AND (&&): Returns true if both operands are true.
○ int result = (5 > 3 && 8 > 6); // result = 1 (true)
● Logical OR (||): Returns true if at least one of the operands is true.
○ int result = (5 > 3 || 8 < 6); // result = 1 (true)
● Logical NOT (!): Returns true if the operand is false.
○ int result = !(5 > 3); // result = 0 (false)
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a = 5;
int b = 5;
printf("Result is: %d\n", (a == 5 && b == 5));
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
4. Bitwise Operators
PICT, Pune. Mrs. Madhuri S. Patil
4. Bitwise Operators
These operators perform operations on the binary representation of integers:
● Bitwise AND (&): Performs a binary AND operation.
○ int result = 5 & 3; // result = 1 (binary 0101 & 0011 = 0001)
● Bitwise OR (|): Performs a binary OR operation.
○ int result = 5 | 3; // result = 7 (binary 0101 | 0011 = 0111)
● Bitwise XOR (^): Performs a binary XOR operation.
○ int result = 5 ^ 3; // result = 6 (binary 0101 ^ 0011 = 0110)
● Bitwise NOT (~): Performs a binary NOT operation (bitwise complement).
○ int result = ~5; // result = -6 (binary ~0101 = 1010)
● Left shift (<<): Shifts the bits of the first operand to the left by the number of positions specified by
the second operand.
○ int result = 5 << 1; // result = 10 (binary 0101 << 1 = 1010)
● Right shift (>>): Shifts the bits of the first operand to the right by the number of positions specified
by the second operand.
○ int result = 5 >> 1; // result = 2 (binary 0101 >> 1 = 0010)
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a = 5; // In binary: 0101
int b = 7; // In binary: 0111
int result=(a&b);
printf(“result is %d”,result);
printf("Result of a & b: %d\n", (a & b));
printf("Result of a | b: %d\n", (a | b));
return 0;
}
0101 & 0111 ------- 0101 0101 |
0111
PICT, Pune.------- 0111 Mrs. Madhuri S. Patil
5. Assignment Operators
These operators are used to assign values to variables:
● Assignment (=): Assigns a value to a variable.
○ int x = 10; // x is assigned the value 10
● Add and assign (+=): Adds the right operand to the left operand and assigns the result to the left operand.
○ int x = 10;
x += 5; // x = 15
● Subtract and assign (-=): Subtracts the right operand from the left operand and assigns the result to the left operand.
○ int x = 10;
x -= 5; // x = 5
● Multiply and assign (*=): Multiplies the left operand by the right operand and assigns the result to the left operand.
○ int x = 10;
x *= 5; // x = 50
● Divide and assign (/=): Divides the left operand by the right operand and assigns the result to the left operand.
○ int x = 10;
x /= 5; // x = 2
● Modulus and assign (%=): Computes the modulus of the left operand by the right operand and assigns the result to the left
operand.
○ int x = 10;
PICT, Pune. x %= 3; // x = 1 Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a = 5;
int b = 7;
a = b;
printf("After a = b, a = %d\n", a);
a += 2; // Equivalent to: a = a + 2;
printf("After a += 2, a = %d\n", a);
a -= 3; // Equivalent to: a = a - 3;
printf("After a -= 3, a = %d\n", a);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
6. Increment and Decrement Operators
These operators are used to increase or decrease the value of a variable by one:
● Increment (++): Increases the value of the operand by one.
○ int x = 5;
x++; // x = 6
● Decrement (--): Decreases the value of the operand by one.
○ int x = 5;
x--; // x = 4
Prefix and Postfix Notation:
● Prefix: ++x or --x (increments/decrements before using the value).
● Postfix: x++ or x-- (increments/decrements after using the value).
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a = 5;
printf("a:%d\n",a++);
printf("a:%d\n",++a);
a--;
printf("a:%d\n",a);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
7. Conditional (Ternary) Operator:
The conditional operator is a shorthand for the if-else statement:
int max = (a > b) ? a : b; // Assigns the greater of a and b to max
8. Comma Operator
The comma operator allows multiple expressions to be evaluated in a single statement, with the result of the last
expression being used.
int x = (printf("Hello "), 5); // Prints "Hello" and assigns 5 to x
printf("x:%d\n",x);
9. Sizeof Operator
The sizeof operator returns the size (in bytes) of a data type or variable.
int size = sizeof(int); // size holds the number of bytes occupied by an int
10. Pointer Operators
● Address-of Operator (&): Returns the address of a variable.
int x = 5;
PICT, Pune. int *ptr = &x; // ptr holds the address of x Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a=10;
int size=sizeof(a);
printf("size is:%dbytes",size);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
Example:
#include <stdio.h>
int main() {
int a = 10;
int b = 20;
int size = sizeof(a);
int max = (a > b) ? a : b;
printf("The maximum of %d and %d is %d.\n", a, b, max);
printf("Size of int: %d bytes\n", size);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
Notion of Assembler:
An assembler is a tool or software that translates assembly language code into machine code, which is the binary code (0’s and 1’s)
Assembly language example
MOV AX, 1 ; Move value 1 into register AX
ADD AX, 2 ; Add value 2 to register AX
PICT, Pune. Mrs. Madhuri S. Patil
Compiler and Interpreter:
Compilers are tools that translate high-level code into a machine code in one go.
Interpreter translates high-level code into machine code or intermediate code line-by-line
PICT, Pune. Mrs. Madhuri S. Patil
Compiler Interpreter
Compilers are tools that translate high-level code into a machine code in Interpreter translates high-level code into machine code or intermediate
one go. code line-by-line
The compiler saves the Machine Language in form of Machine Code on The Interpreter does not save the Machine Language.
disks.
Compiled codes run faster than Interpreter. Interpreted codes run slower than Compiler.
Linking-Loading Model is the basic working model of the Compiler. The Interpretation Model is the basic working model of the Interpreter.
The compiler generates an output in the form of (.exe). The interpreter does not generate any output.
Any change in the source program after the compilation requires re- Any change in the source program during the translation does not require
compiling the entire code. retranslation of the entire code.
Execution of the program takes place only after the whole program is Execution of the program happens after every line is checked or evaluated.
compiled.
CPU utilization is more in the case of a Compiler. CPU utilization is less in the case of a Interpreter.
Object code is permanently saved for future use. No object code is saved for future use.
C, C++, C#, etc are programming languages that are compiler- Python, Ruby, Perl, SNOBOL, MATLAB, etc are programming
based. languages that are interpreter-based.
PICT, Pune. Mrs. Madhuri S. Patil
Difference Between Assembler Compiler And Interpreter:
PICT, Pune. Mrs. Madhuri S. Patil
Interpreter and Compiler:
Compiler Interpreter
GCC (GNU Compiler Collection) CINT
Clang Ch
Microsoft Visual C++ (MSVC) C Script
Borland C++ Compiler PUC-Rio C Interpre
Intel C++ Compiler (ICC) Cling
PICT, Pune. Mrs. Madhuri S. Patil
Compilation:
A computer program that translates C code into machine code
Hello.c c compiler [Link](windows)
[Link](linux)
PICT, Pune. Mrs. Madhuri S. Patil
ASCII Value Example:
// C program to print ASCII Value of Character using
// implicit conversion with format specifier.
#include <stdio.h>
int main() {
char c = 'k';
// %d displays the integer value of
// a character
// %c displays the actual character
printf("The ASCII value of %c is %d", c, c);
return 0;
}
PICT, Pune. Mrs. Madhuri S. Patil
Questions:
PICT, Pune. Mrs. Madhuri S. Patil