CSE 1321 LATEST EXAM TEST 2026/2027 QUESTIONS
AND SOLUTIONS RATED A+
✔✔Variable = expression; - ✔✔1) the expression on the right side of the = operator is
evaluated Expression has data type and value
2) the result is stored in the variable on the left if the types are compatible (overwriting
the original value)
✔✔Shortcut Operators - ✔✔++ increment by 1
-- decrement by 1
+= a += 3; a = a + 3;
-= a -=10; a= a-10;
*= a*=4; a= a*4;
/= a/=7; a= a / 7;
%= a%=10; a= a % 10;
✔✔Two Types of Data Conversion - ✔✔-Widening conversion (promotion)
-Narrowing conversion (demotion)
✔✔Widening conversion (promotion) - ✔✔-safe, do not lose data
-goes to a "wider" (more bits) data type
-may lose precision (long to float)
✔✔Narrowing conversion (demotion) - ✔✔-may lose data
-may lose precision
-should be avoided
-compiler error unless specific cast done
✔✔Conversion Techniques - ✔✔- Assignment conversion
Example: assign an int to a long
-Promotion
Example: divide an int by a double
- Casting
Example: assign a double to int
✔✔Explicit Type Casting - ✔✔Syntax:
(dataType)(expression)
Note: parentheses around the expression are optional if the expression consists of 1
variable
, Useful for calculating averages:
double result = (double) 25/3;
double result = (double) total / count;
✔✔Expression evaluation follow - ✔✔operator precedent rule (order of operations).
✔✔The order of statement execution is called the - ✔✔flow of control
✔✔By default, execution is - ✔✔linear: one statement after another
✔✔A ------- allows us to choose which statements will be executed next: - ✔✔Selection
(conditional) statement
✔✔if - ✔✔if - block of code executes if a Boolean expression is true.
(selection statement)
✔✔if-else - ✔✔will execute one block of code if the Boolean expression is true, or
another if it is false.
(selection statement)
✔✔if-else-if - ✔✔tests a series of Boolean expressions and execute corresponding
block when it finds one that is true.
(selection statement)
✔✔switch - ✔✔lets the value of a variable determine where the program will branch to.
✔✔Relational Operators - ✔✔Create a true or false using a relational operator:
> greater than
< less than
== equals
! not
!= not equal
>= greater than or equal
<= less than or equal
✔✔!
!= - ✔✔not not equal to (relational operators)
✔✔Logical Operators - ✔✔Boolean expressions can also use the following logical
operators:
Logical NOT
Logical AND
Logical OR
AND SOLUTIONS RATED A+
✔✔Variable = expression; - ✔✔1) the expression on the right side of the = operator is
evaluated Expression has data type and value
2) the result is stored in the variable on the left if the types are compatible (overwriting
the original value)
✔✔Shortcut Operators - ✔✔++ increment by 1
-- decrement by 1
+= a += 3; a = a + 3;
-= a -=10; a= a-10;
*= a*=4; a= a*4;
/= a/=7; a= a / 7;
%= a%=10; a= a % 10;
✔✔Two Types of Data Conversion - ✔✔-Widening conversion (promotion)
-Narrowing conversion (demotion)
✔✔Widening conversion (promotion) - ✔✔-safe, do not lose data
-goes to a "wider" (more bits) data type
-may lose precision (long to float)
✔✔Narrowing conversion (demotion) - ✔✔-may lose data
-may lose precision
-should be avoided
-compiler error unless specific cast done
✔✔Conversion Techniques - ✔✔- Assignment conversion
Example: assign an int to a long
-Promotion
Example: divide an int by a double
- Casting
Example: assign a double to int
✔✔Explicit Type Casting - ✔✔Syntax:
(dataType)(expression)
Note: parentheses around the expression are optional if the expression consists of 1
variable
, Useful for calculating averages:
double result = (double) 25/3;
double result = (double) total / count;
✔✔Expression evaluation follow - ✔✔operator precedent rule (order of operations).
✔✔The order of statement execution is called the - ✔✔flow of control
✔✔By default, execution is - ✔✔linear: one statement after another
✔✔A ------- allows us to choose which statements will be executed next: - ✔✔Selection
(conditional) statement
✔✔if - ✔✔if - block of code executes if a Boolean expression is true.
(selection statement)
✔✔if-else - ✔✔will execute one block of code if the Boolean expression is true, or
another if it is false.
(selection statement)
✔✔if-else-if - ✔✔tests a series of Boolean expressions and execute corresponding
block when it finds one that is true.
(selection statement)
✔✔switch - ✔✔lets the value of a variable determine where the program will branch to.
✔✔Relational Operators - ✔✔Create a true or false using a relational operator:
> greater than
< less than
== equals
! not
!= not equal
>= greater than or equal
<= less than or equal
✔✔!
!= - ✔✔not not equal to (relational operators)
✔✔Logical Operators - ✔✔Boolean expressions can also use the following logical
operators:
Logical NOT
Logical AND
Logical OR