Lecture05-w02-LIN-09132019-Variable2Int.pdf - Computing I COMP.1010 Fall 2019 Lecture 5 Variables int type By Sirong Lin PhD University of Massachusetts

Lecture05-w02-LIN-09132019-Variable2Int.pdf - Computing I...

This preview shows page 1 - 12 out of 38 pages.

Computing I By: Sirong Lin, PhD University of Massachusetts Lowell COMP.1010, Fall 2019 Lecture 5: Variables, int type
Image of page 1
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Upcoming Due Dates 2 Due Date Daily 03 09-13-2019 (F), 9:00pm Week 02 Practice 09-15-2019 (Su), 9:00pm Week 03 Reading 1, 2, 3 MWF, 9:00am Week 03 Practice 09-22-2019 (Su), 9:00pm Daily 04 09-16-2019 (M), 9:00pm Daily 05 09-18-2019 (W), 9:00pm
Image of page 2
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Outline Variable in C (Cont’d) int data type & int variable 3
Image of page 3
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Variable in C Review Variable in C is a named place/location in memory a real place, NOT a placeholder! 4
Image of page 4
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Variable in C — Variable declaration MUST declare a variable before use — Variable declaration 1. tell the compiler the name of the variable 2. which kind of information will be stored in the variable and how to interpret the data 5
Image of page 5
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin 6 Variable in C (Cont’d) Declare a variable — Syntax data_type variable_name; int number; char letter; double rate; int, char, double: C datatypes number , letter , rate are variable names
Image of page 6
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin 7 Variable in C (Cont’d) What happen internally when we declare a variable int number; claim 4 bytes for an integer give it a name at the first address number the contents inside the memory will be interpreted as an integer value (in two’s complement)
Image of page 7
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Variable in C — Definition Variable in C is a named place/location in memory a real place, NOT a placeholder! must be declared before use (otherwise, no memory associated) 8
Image of page 8
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Variable in C — use in program After variable declaration, when we use a variable name, we refer to the value of that variable (contents stored in its memory place) 9 int number; printf("%d\n", number );
Image of page 9
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Variable in C (Cont’d) variable number has contents has an address use address of operator &, e.g., &number gets the memory address: 2423452 10 number
Image of page 10
Work Ready Life Ready World Ready Computing I, F2019, By Dr. Sirong Lin Variable in C (Cont’d) Exercise:
Image of page 11
Image of page 12

You've reached the end of your free preview.

Want to read all 38 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

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes