Lecture16-LIN-10092019-Scope-PrePostfix-LibFunctions.pdf - Computing I COMP.1010 Fall 2019 Lecture 16 Library functions Scope of Names Prefix Postfix

Lecture16-LIN-10092019-Scope-PrePostfix-LibFunctions.pdf -...

This preview shows page 1 - 13 out of 44 pages.

Computing I By: Sirong Lin, PhD University of Massachusetts Lowell COMP.1010, Fall 2019 Lecture 16: Library functions, Scope of Names, Prefix/ Postfix Incremental
Image of page 1
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Upcoming Due Dates 2 Due Date Program 1 10-09-2019 (W), 9:00pm Daily 13 10-09-2019 (W), 9:00pm Week 06 Readings MWF, 9:00am HW2 10-11-2019 (F), in class Daily 14 10-11-2019 (F), 9:00pm Quiz for HW1 10-11-2019 (F), 9:00pm HW3 10-15-2019 (Tu), in class
Image of page 2
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Announcement Exam 1: Oct. 16, in class, 50 minutes Prepare to write for the whole 50 minutes Talk with me by this Friday if you have special requirement (e.g., longer time) how to prepare: write more code, e.g., redo daily programming assignments, practice questions on zyBook 3
Image of page 3
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Exam Format explain a concept write output for a piece of C code write C code (complete program or a fragment) to implement the required functionality identify errors/problems in the code NO syntax errors in the code evaluate expressions binary conversion (2’s Complement) 4
Image of page 4
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Outline Library functions Scope of Names Prefix & Postfix Incremental 5
Image of page 5
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Library functions 6
Image of page 6
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Library Functions predefined functions in C libraries standard input and output: stdio.h general library: stdlib.h math library: math.h #include <math.h> notifies the preprocessor that some names used in the program are found in this library 7 include directive
Image of page 7
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin stdlib.h Library Functions 8 in stdlib.h returns the absolute value of its integer argument x int abs(int x);
Image of page 8
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin stdlib.h Library Functions — abs 9 int y = abs(-56); abs (calculate the absolute value of an integer) x absolute value of x -56 (argument) 56 -56 is called argument evaluate expression abs(-56) first; assign the value 56 (result of abs) to y y has the value of 56 after the assignment
Image of page 9
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Library Functions (Cont’d) What is the value of this expression? evaluate abs(-20), abs(6) — function has the highest precedence abs(-20) is 20, abs(6) is 6 6/20 is 0 (integer division), so the expression evaluates to 0 10 abs(6) / abs(-20)
Image of page 10
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Library Functions (Cont’d) 11 x is 3.0 x is 3.3333 double x = abs(-20) / abs(6); double x = (double) abs(-20) / abs(6);
Image of page 11
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin stdlib.h Library Functions — abs (Cont’d) Write a complete C program to output the absolute value from -50 to 50 by calling abs function, one number per line.
Image of page 12
Image of page 13

You've reached the end of your free preview.

Want to read all 44 pages?

  • Fall '15

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors