450 likes | 466 Views
Explore bitwise manipulation and assignment operators in programming. Learn about bitwise AND, OR, XOR operators, assignment operations, design recipes, data types, arithmetic operators, logical/legal/bitwise operators, and loop constructs.
E N D
Introduction to Programming Lecture 22 Review
Bit wise Manipulation and Assignment Operator
a = a + 1 ; a += 1 ;
Bit Manipulation Operators &= Bitwise AND Assignment Operator |= Bitwise OR Assignment Operator ^= Bitwise Exclusive OR Assignment Operator
Assignment Operator a &= b ; Same as a = a & b ;
Assignment Operator a |= b ; Same as a = a | b ;
Assignment Operator a ^= b ; Same as a = a ^ b ;
Design Recipes • Analyze a problem statement, typically expressed as a word problem • Express its essence, abstractly and with examples • Formulatestatements and comments in a precise language • Evaluate and revise the activities in the light of checks and tests. • PAY ATTENTION TO DETAIL
Symbolic Names x i BasicPay HouseRent
Data types • Whole numbers: • int, short, long, unsigned • Real Numbers (with decimal points) • float, double • Character data • char
int = 4 bytes char = 1 byte
Arithmetic Operators Plus + Minus - Multiply * Divide / Modulus %
Modulus Operator a % b ; 7 % 2 = 1 ; 100 % 20 = 0 ;
Compound Arithmetic Operators += -= *= /= %=
Compound Arithmetic Operators a = a + b ; a += b ;
Logical Operators AND && OR ||
Comparison Operators a < b ; a <= b ; a == b ; a >= b ; a > b ;
if ( a = b ) //Wrong //Logical Error
a > b ; a >= b ;
Bit wise Operators Bit wise AND & (Binary) Bit wise OR | (Binary) Bit wise Exclusive OR ^ (Binary) NOT ~ (unary)
Sequential Construct • Decision Construct • Loop Construct
If-statement if ( condition ) { statement ( s ) ; }
If-else if ( condition ) { statement ( s ) ; } else { statement ( s ) ; }
if ( condition ) { statement ( s ) ; if ( condition ) { statement ( s ) ; } statement ( s ) ; }
While Loops while ( a > b ) { statement ( s ) ; }
While Loops While loop executes zero or more times
Do - while do { statement ( s ) ; } while ( condition ) ;
Do - while Do-while loop executes one or more times
For Loops for ( i = 0 ; i < 10 ; i ++ ; ) { statement ( s ) ; }
i = i + 1 ; • i += 1 ; • i ++ ;
break ; • continue ;
Call by value • Call by reference
Arrays int a [ 10 ] ; a [ 0 ] ; : a [ 9 ] ;
Pointers Memory address of a variable is stored inside a pointer
Files and their Input / Output systems