CSC161 2010F, Class 06: Types and Operators Overview: * Questions and Answers. * Hello World. * Compiling C Programs. * C Beyond K&R. * Back to the Basics. * Lab (if time permits). Admin: * Mostly lecture/discussion today * I hope to respond to Assignment 1 tonight or tomorrow night. * Are there questions on Assignment 2? * For tomorrow, read sections 7.1-7.4 of K&R. * Many of the examples from today's class can be found in Examples/Compiling in the course web. * EC for Charles's and Kumail's comedy on Wednesday at 8 p.m. in Harris * Congrats to soccer! Q&A on Chapter 2 of K&R (gathered, not necessarily answered) * Bitwise stuff is confusing - Information coming on Friday * Too sophisticated - Solution: Look forward to the lab in which stuff makes sense * All these character constants and weird octal things and such * Hard to see what's important and what's just "ooh, look, you can do this in C" * Why do we have a character type when characters are integers anyway? The legendary "Hello World" * You did a nice job of applying GNU standards How to compile C programs in the MathLAN * See the outline Looking a bit beyond K&R. * Always return from main 0 - success postiive number - failure * #include EXIT_SUCCESS EXIT_FAILURE * #include (We'll look at this later.) C Basics * Variable Names * In C: sequence of letters, numbers, and underscore charactersw that do not begin with a number. OK hello l33t _this_variable_stores_a_really_useless_value Not OK 3tt he-llo for, int, while * Standard: Only the first six characters are guaranteed to be significant * Our system: At least 1000 characters are significant * Declarations * Requires explicit declaration and typing TYPE NAME; int i; TYPE NAME1, NAME2, NAME3; double i, j, k; * Assignment Statements VAR = EXP; Meaning: Evaluate the expression and shove the result in the memory associated with the variable. x = 2; x = x * 5; * Primary Types char, int, short, long, float, double * All of these are FIXED-SIZE. You can't store arbitrary numbers. * Need to distinguish between SIGNED (positive or negative) and UNSIGNED (only positive) for integer types * chars are just integers (small integers) * So why do we have them? * Save space (written in an era when memory was expensive) * We want to think of a character type, even if there's not really one, because it's easier to write, say 'A' than 65 * Constants * Way too many ways to notate. Don't worry about anything that's not plain decimal right now. * Enums * Your own finite type enum NAME { VAL1, VAL2, VAL3 }; enum CSC161 { Radhika, Daryl, Nolen, Etc }; enum CSC161 student_to_call_on; student_to_call_on = Daryl; student_to_call_on = 5; int i = Daryl; ++student_to_call_on; These values in an enum are constants, not variables * And more? Lab