Week 4.docx

4 Pages
37 Views

Department
Electrical & Computer Engineer
Course Code
ECE 15
Professor
Alon Orlitsky

This preview shows page 1. Sign up to view the full 4 pages of the document.
Description
1. Macros a. If you want to change a constant that appears in multiple locations, you can set that constant as a variable, and change the one variable declaration instead. However, the variable won’t change unless reset manually. b. You could use #define MAX 9, and all MAX variables are substituted into 9. This is supposedly more “computer” efficient, as it defines MAX as 9 before it reads the program during compiling. But cannot be re-declared by the program itself, unlike with variables. Otherwise, it operates the exact same way as a variable would. c. Conventionally, macros are written in UPPERCASE and variables are written in lowercase. 2. Largest non-decreasing substrings a. Input: a sequence of positive integers, followed by a single number less than 0 b. The largest non-decreasing substring is the largest set of contiguous numbers that does not decrease. c. If there are none, the largest value will be chosen. i. Ex: 1 2 1 4 4 2 -1: Largest substring is 3 d. Variables i. current_value: the current value in the sequence ii. previous_value: the previous sequence value iii. current_length: current length of non-decreasing sequence iv. longest_length: longest length of non-decreasing sequence 1. These are all considered integer types. v. This works in one series of input because “scanf()” works in buffers; it will read one integer after the other, and determine sequences of the integers it has currently read AS it reads all the integers input. 3. Break and Continue a. Jump statements change the loop’s default behavior: i. break – Imeediate loop exit. Rest of loop skipped. ii. continue – the rest of iterations below this function are skipped, but the execution still proceeds to the next loop iteration; this works only for loops, and not switch. 4. Infinite Loops a. Infinite loops can be intentional through: i. while (1) {…} ii. for ( ;1; ) {…} iii. for ( ; ; ; ) {…} 1. These loops can be exited via: “break”, “return”, or “goto” within the loop itself. b. An index of a loop determines how many times a loop will run. i. Ex: for (i=0; i
More Less
Unlock Document

Only page 1 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit