Presentation is loading. Please wait.

Presentation is loading. Please wait.

UMBC CMSC 104 – Section 01, Fall 2016

Similar presentations


Presentation on theme: "UMBC CMSC 104 – Section 01, Fall 2016"— Presentation transcript:

1 UMBC CMSC 104 – Section 01, Fall 2016
Exam 2 Review

2 Notes & Announcements Project 8 due… now!
Will review in a moment Today is final day to fill out course evals Look for from

3 Final Exam The final exam is scheduled for: Thursday, December 15th
6:00 – 8:00 PM Engineering 122 (here) The exam will be on paper – bring a pencil! You may bring a calculator. You probably won’t need it. NO PHONES OR COMPUTER USAGE ALLOWED Bring your UMBC ID!

4 Requesting Feedback Did you prefer the course website over Blackboard? Why? Would you have preferred less projects and another exam? Why? Would you have preferred more in-class labs, assuming they didn’t count for EC? Other comments?

5 Exam 2 Review

6 Overview If it’s in the slides, it’s fair game Broad Concepts
Arithmetic Ops (+, -, *, /, %) Assignment Ops (++, --, +=, -=, etc) Relational Ops & Selection Statements (if, else if, else) For loops and While loops Switch Statements Functions Arrays Searching & Sorting Algorithms Pointers

7 Arithmetic Operators in C
Name Operator Example Addition + num1 + num2 Subtraction - initial – spent Multiplication * fathoms * 6 Division / sum / count Modulus % m % n

8 Rules of Operator Precedence
Operator(s) Precedence & Associativity ( ) Evaluated first. If nested (embedded), innermost first. If on the same level, left to right. * / % Evaluated second. If there are several, evaluated left to right. + - Evaluated third. If there are several, evaluated left to right. = Evaluated last, right to left.

9 Increment and Decrement Operators
The increment operator ++ The decrement operator -- Precedence: lower than (), but higher than * / and % Associativity: right to left Increment and decrement operators can only be applied to variables, not to constants or expressions

10 Assignment Operators = += -= *= /= %= Statement Equivalent Statement
= += -= *= /= %= Statement Equivalent Statement a = a + 2 ; a += 2 ; a = a - 3 ; a -= 3 ; a = a * 2 ; a *= 2 ; a = a / 4 ; a /= 4 ; a = a % 2 ; a %= 2 ; b = b + ( c + 2 ) ; b += c + 2 ; d = d * ( e - 5 ) ; d *= e - 5 ;

11 Relational Operators Relational expressions evaluate to the integer
< less than > greater than <= less than or equal to >= greater than or equal to == is equal to != is not equal to Relational expressions evaluate to the integer values 1 (true) or 0 (false). All of these operators are called binary operators because they take two expressions as operands.

12 Logical Operators So far we have seen only simple conditions.
if ( count > 10 ) . . . Sometimes we need to test multiple conditions in order to make a decision. Logical operators are used for combining simple conditions to make complex conditions. && is AND if ( x > 5 && y < 6 ) || is OR if ( z == 0 || x > 10 ) ! is NOT if (! (bob > 42) )

13 Nesting of if-else Statements
if ( condition1 ) { statement(s) } else if ( condition2 ) /* more else clauses may be here */ else statement(s) /* the default case */

14 The while Repetition Structure
while ( condition ) { statement(s) } The braces are not required if the loop body contains only a single statement. However, they are a good idea and are required by the 104 C Coding Standards.

15 The for Loop Repetition Structure
The for loop handles details of the counter-controlled loop “automatically”. The initialization of the loop control variable, the termination condition test, and control variable modification are handled in the for loop structure. for ( i = 1; i < 101; i = i + 1) { initialization modification } test

16 The switch Multiple-Selection Structure
switch ( integer expression ) { case constant1 : statement(s) break ; case constant2 : . . . default: }

17 Examining PrintMessage
#include <stdio.h> void PrintMessage ( void ) ; function prototype int main ( ) { PrintMessage ( ) ; function call return 0 ; } void PrintMessage ( void ) function header printf (“A message for you:\n\n”) ; function printf (“Have a nice day!\n”) ; body } function definition

18 Array Declaration and Initialization
int numbers[5] ; The name of this array is “numbers”. This declaration sets aside a chunk of memory that is big enough to hold 5 integers. It does not necessarily initialize those memory locations to 0 or any other value. They may contain garbage. Initializing an array may be done with an array initializer, as in : int numbers[5] = { 5, 2, 6, 9, 3 } ; numbers 5 2 6 9 3

19 Accessing Array Elements
Each element in an array has a subscript (index) associated with it. Subscripts are integers and always begin at zero. Values of individual elements can be accessed by indexing into the array. For example, printf(“The third element = %d.\n”, numbers[2]); would give the output The third element = 6. numbers 5 2 6 9 3

20 Don’t Forget… Searching & Sorting Pointers Searching Algorithms
Sorting Algorithms Efficiency Pointers Definition of a pointer Types of pointers Uses for pointers

21 Questions?


Download ppt "UMBC CMSC 104 – Section 01, Fall 2016"

Similar presentations


Ads by Google