Lecture 5 - Errors, Operators Conditional Statements
Lecture 5 - Errors, Operators Conditional Statements
https://padlet.com/saratariq4/c-starter-
luedenkideynlm92
5 101
3 011
1 0 1
1 1 1
0 1 1
Binary Decimal
111 7
So, x |= 3 is equal to 7.
x ^= 3 XOR assignment operator • If the bits are the same (0,0 or 1,1),
the result is 0.
• If the bits are different (0,1 or 1,0),
the result is 1.
x >>= 3 Right shift assignment operator • Moves each bit 3 positions to the
right, discarding the rightmost bits
and filling the leftmost bits with 0s
• For positive numbers, >> divides
by powers of 2.
x <<= 3 Left shift assignment operator • Moves each bit 3 positions to the
left, shifting in zeros (0) from the
right
• Left shifting (<<) multiplies the
number by powers of 2.
• Each left shift operation (x << n) is
equivalent to x * (2^n).
• Shifting too far left can cause
overflow if the number exceeds
the variable's bit capacity.
int main() {
int x = 5;
int y = 3;
cout << (x > 3 && x < 10);
return 0;
}
++ -- Increment/Decrement Right
| Bitwise OR Left
|| Logical OR Left
, Comma Left 15
Example
#include <iostream>
using namespace std;
int main() {
int x = 5;
cout << !(x > 3);
return 0;
}
• int result = 10 + 3 * 2 / (6 - 4) % 2;
int main() {
int x = 5;
int y = 3;
cout << (!(x < 3) && (y == 3 || x < 10));
return 0;
}
• Algorithm Representation
• Pseudocode
• Flowchart
Operators, Algorithms, and Conditional Statements 26
Pseudocode
• Pseudocode is a technique used to describe the steps of an
algorithm in a manner that's easy to understand for anyone with
basic programming knowledge
BEGIN
DISPLAY “Enter Temperature in Centigrade: ”
INPUT centigrade_value
CALCULATE Fahrenheit = (1.8 * centigrade_value) + 32
DISPLAY Fahrenheit
END
BEGIN
n ← 50
sum ← (n * (n + 1)) / 2
DISPLAY "The sum of the first 50 natural numbers is:", sum
END
BEGIN
sum ← 0 // Initialize sum to 0
FOR i FROM 1 TO 50 DO
sum ← sum + i // Add current number to sum
ENDFOR
DISPLAY "The sum of the first 50 natural numbers is:", sum
END
Input / Output:
• A parallelogram denotes any function of input/output type
• Take input from input devices
• Display output on output devices
Processing:
• A rectangle represents processing & operations
• All arithmetic processes are indicated by the action or process symbol
Connectors:
• A circle symbol is used to connect multiple flowcharts
• Complex and large flowcharts are divided into smaller ones for easy
display.
Flow Lines:
• Arrow shows the direction of flow of instructions