Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez

Similar presentations


Presentation on theme: "COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez"— Presentation transcript:

1 COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez djrg@cise.ufl.edudjrg@cise.ufl.edu http://cise.ufl.edu/~djrg/http://cise.ufl.edu/~djrg/ https://ufcprog2015.wordpress.com/

2 ADMINISTRATIVE STUFF New rule: whenever you participate tell me your name! Homework #1is available for submission via Canvas! Did you guys register for a CISE account? If not, do so soon! http://register.cise.ufl.edu/http://register.cise.ufl.edu/ You should have heard back already if you registered on Monday. Takes 2-3 business days for them to get back. If you haven’t submitted your registration yet, I’m afraid you won’t be able to test your Homework 1 on the server  If we need to, I’ll cover a few alternatives. (Disclaimer: None of them can guarantee 100% that it would be as effective as trying it directly on the server)

3 ALTERNATIVES FOR THE PROCRASTINATORS Ask one of your classmates that does have an account to help you test. If you do so, be careful to abide by the Honor code! Please don’t cheat! I’m starting to like you. I won’t teach anything about these, and can’t guarantee it will be the same as the server, but: At the very least test in CodeBlocks (free, good IDE, available for Windows and Mac)CodeBlocks You could potentially use MinGW (Linux simulator for Windows)MinGW

4 VARIABLES AND TYPES

5 WHAT IS A VARIABLE? Similar to what a variable is in Algebra/Math. A variable is “something” in my program that stores a value

6 STORING VALUES Remember computers work in binary: 1 or true (high voltages) 0 or false (low voltages) Potential instruction: 10010101011100011100101110101010 Everything we store in a computer is eventually a long binary number. Numbers Text Photos Music Videos

7 UNITS OF MEASURE IN BINARY Name (abbreviation) Size Bit (b)1 single binary digit (0 or 1) Byte (B)8 bits Kilobyte (KB)1024 bytes Megabyte (MB)1024 KB Gigabyte (GB)1024 MB Terabyte (TB)1024 GB Petabyte (PB)1024 TB Notice how elegant: everything is a power of 2! 2 0 = 12 3 = 82 10 = 1024

8 MEMORY (RAM) VS. HARD DRIVE Disclamer: I’m oversimplifying a bit of this content to make it easier to understand. Who has ever carefully selected a computer? By looking at the tech specs, not how shinny it looked. What do “ memory ” and “ hard disk drives ” have in common? Devices (parts of a computer) that store information Units in which we measure their size Gigabytes (GB) or Terabytes (TB)

9 MEMORY VS. HARD DRIVE UsuallyMemoryHard Drive More storage? Faster access? More expensive? More relevant to today’s class? Where do programs usually “live”? Does not require power to keep information During executionAt any other time

10 SO WHAT, DIEGO? WHY DO WE CARE? Because “something” A variable is “something” in my program that stores a value So “something” is actually a space in memory! A variable is a space in memory where my program will store a value Each variable is associated with a type that tells us how to interpret the binary number stored at that location

11 DEFINING AND ASSIGNING VARIABLES The basic definition for a variable is going to look like this: ; is like a “name”. It can be almost anything! Rules: Starts with an alphabetic character (a-z or A-z) or an underscore (‘_’) – That’s not an emoticon… Can contain alphabetic characters (a-z and/or A-z), numbers (1-9) and underscores (‘_’) No spaces, no other weird characters. Good practices tell us it should be something meaningful. Choosing good identifiers for our variables is important. "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Rick Osborne

12 EXAMPLES OF VARIABLE IDENTIFIERS Valid sum Flag myFirstResult Variable_1 adorable_penguin_1002 _this6thVariableIHaveNoIdeaWhatToName Please notice that “being valid” and “being meaningful” are very different.

13 EXAMPLES OF VARIABLE IDENTIFIERS Invalid 101Dalmatians $money #why_does_C_hates_hashtags May_I_ask_you_a_question? my variable

14 WHAT TYPES ARE AVAILABLE TypeValues intInteger numbers (no decimals) floatNumbers, including those with decimals doubleA float with more “precision” charA single character. ‘A’ for example. _BoolEither a 1 or a 0 (true or false)

15 EXAMPLES OF VARIABLE DEFINITIONS int sum; _Bool Flag; float myFirstResult; char Variable_1; double adorable_penguin_1002; int _this6thVariableIHaveNoIdeaWhatToName; Do I have to define all variables separately? What if I want to define 3 integers quickly?

16 DEFINING MULTIPLE VARIABLES IN A SINGLE LINE int sumA, sumB; _Bool Flag1, Flag2, Flag3; float myFirstResult, mySecondResult; char Variable_1, Variable_2; double adorable_penguin_1002, adorable_penguin_1003; Separate identifiers with commas. In this case both sumA And sumB would have type integer.

17 ASSIGNING VALUES TO A VARIABLE The basic assignment structure is: = ; could be a constant or some calculation. For now let’s talk about constants. Examples: TypeExamples (separated by commas) int0, 100, -200, -1717, 12345 float0.100, 3.1415, -100.300f, 90.84F double0.100L, 3.1415l, -100.02 char‘a’, ‘b’, ‘#’, ‘_’, ‘\n’. ‘\’’, ‘\\’ _Bool1, 0

18 EXAMPLES! int sum; sum = 100; float myFirstResult; myFirstResult = 0.01f; Ugh! Two lines to define and assign my variable… that is so tedious.. Is there a more efficient way?

19 EXAMPLES int sum = 100; float myFirstResult = 0.01f; char Variable_1 = ‘D’; /*Why ‘D’ you ask? Well… it starts my name after all… */ So much theory… Let’s test it!

20 PRINTING A VARIABLE We will use, surprise surprise printf How? By using a special character in the string… Each type uses a different character, we will need to learn them… TypePrintf characters int%i, %x, %o float%f, %e, %g, %a double%f, %e, %g, %a char%c _Bool%i, %u

21 PRINTING A VARIABLE #include int main(void) { int grade = 100; printf("I will get a %i in my first C HW\n", grade); return 0; }

22 PRINTING A VARIABLE #include int main(void) { char letter = 100; printf("I will get a %i in my first C HW\n“, sum); return 0; }

23 PRINTING TWO OR MORE VARIABLES #include int main(void) { char letter = 100; printf("I will get a %i in my first C HW\n“, sum); return 0; } #include int main(void) { char letter = 'D'; int grade = 100; printf(“With a %i in my HW I won't get a %c in my C programming class\n", grade, letter); return 0; }

24 TYPE SPECIFIERS Specifier long short unsigned signed So, can I have a infinitely large number stored in a variable of type int?


Download ppt "COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez"

Similar presentations


Ads by Google