1 / 21

Exam 2 Review: C Programming Concepts & Algorithms Overview

Prepare for Exam 2 testing knowledge in C programming, including arithmetic & relational ops, loops, functions, arrays, pointers, and searching/sorting algorithms. Study key concepts for success.

dralph
Download Presentation

Exam 2 Review: C Programming Concepts & Algorithms Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UMBCCMSC 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 email from StudentCourseEvaluations@umbc.edu

  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

  8. Rules of Operator Precedence

  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 = += -= *= /= %= StatementEquivalent 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 < 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 ) { statement(s) } . . . /* 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 : statement(s) break ; . . . default: statement(s) break ; }

  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 necessarilyinitialize 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 0 1 2 3 4

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

  21. Questions?

More Related