Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 2 Programming.

Similar presentations


Presentation on theme: "Unit 2 Programming."— Presentation transcript:

1 Unit 2 Programming

2 Assuming that "final" is an int variable, what is the value of "final" after the following code fragment? final = 17; final /= 3; The result of integer division is truncated, which means that any remainder is discarded. The integer result therefore is 5.

3 Compiling Compiling is the process of converting 'C' program statements into a format the machine can execute (machine language).

4 Wait() The Wait() command is used to pause a program for the number of milliseconds specified in the input parameter. Any turning Motor Modules continue to run during this time.

5 While() loops While() loops are used to execute a section of code until some condition is met, usually until an expression evaluates to FALSE.

6 Assuming "headcount" is a variable of type unsigned char, and its current value is 175, what is the most you can add to it before it starts to wrap? An unsigned char can never be larger than 255 (8 bits). Thus the most you can add is 255 minus 175, or 80.

7 PWM In the context of EasyC, a PWM value of 0 will cause a Motor Module to stop turning.

8 The code "if (students = 14) {conditional code};" ___________.
This is a hard-to-spot program error, where a single equals sign is used instead of a double equals sign. The programmer probably wanted the computer to execute the conditional code only if the value of "students" is 14. However, this error causes the assignment of a non-zero value to "students", which is evaluated as TRUE, and therefore the conditional code is always executed.

9 syntax error A syntax error is when you try to compile a code statement that cannot be understood by the compiler, due to typographic error or improper 'C' format.

10 After the following fragment of code, what is the value of "count"?
count = 5; // Start with 5 count += 25; // Adding 25 yields 30 count -= 10; // Subtracting 10 yields 20 count *= 10; // Multiplying by 10 yields 200 count /= 5; // Dividing by 5 yields 40

11 You have a bin full of good tires ("tires"), and you need to know how many will be left over ("leftovers") after you take out all the full sets of 4. The code would look like: leftovers = tires % 4 The modulus operator (%), called "mod" for short, is used to find the remainder after division.

12 while()" statements You may always nest "while()" statements inside loops of any kind, including "for()" loops.

13 double equals sign, '==' The double equals sign, '==', means a comparison or test is performed. It does not do an assignment.

14 Signed ints versus unsigned ints:
When a variable is declared to be signed, the wrap point is approximately 1/2 as large as that of an unsigned variable. Therefore a signed variable will wrap at a much lower value. This is true at the lower end as well, because signed variables can hold negative values, where the smallest possible value in an unsigned variable is zero.


Download ppt "Unit 2 Programming."

Similar presentations


Ads by Google