CSC113-Programming Fundamentals
Lecture 05
Week 03
Ms. Noor-ul-Huda
Senior Lecturer-I
Department of Computer Science
College of Computer Science and Information Systems
[email protected]
Lecture outcomes:
▪Arithmetic Operators
▪Addition, Subtraction, Multiplication and Division
▪Compound Statements
▪Order of sub-expression evaluation
Arithmetic Operators:
• Arithmetic operators are fundamental in programming and mathematics.
• They are used to perform basic mathematical operations on numbers.
• In computer programming, these operators are often used for calculations
Arithmetic Operators:
• An arithmetic operator performs mathematical operations such as addition, subtraction,
multiplication, division etc on numerical values (constants and variables).
Operator Meaning of Operator
+ addition or unary plus
- subtraction or unary minus
* multiplication
/ division
% remainder after division (modulo division)
Example of Arithmetic Operators:
// Working of arithmetic operators
#include <stdio.h>
int main()
{
int a = 9,b = 4, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);
return 0;
Compound Statements
• Compound statements, also known as block statements, are used to group multiple
statements together into a single block.
• In many programming languages, compound statements are enclosed within curly braces {}.
• They are often used in control structures like loops and conditionals.
Compound Statements
#include <stdio.h>
int main() {
int x = 7;
if (x > 5) {
printf("x is greater than 5.\n");
printf("This is part of the if block.\n");
} else {
printf("x is not greater than 5.\n");
printf("This is part of the else block.\n");
}
Order of Sub-expression Evaluation:
• The order of sub-expression evaluation is essential when it comes to complex expressions.
In most programming languages, sub-expressions are evaluated based on operator
precedence and associativity.
• For example, in the expression a + b * c, multiplication (*) is evaluated before addition (+)
due to their respective precedence levels.
• Parentheses can be used to override this default order.
#include <stdio.h>
int main() {
int num = 5;
// Using the increment operator to increase num by 1
num++; // Equivalent to num = num + 1;
printf("After incrementing: %d\n", num); // Output will be 6
return 0;
}