CS208 Introduction to Computer Systems Monday, 2 October 2023 + Let's do the quiz together char buffer[100]; strcpy(buffer, "rhinoceros"); char *p = buffer; 1. strlen(p) [10] 2. sizeof(p) [8] See spreadsheet 3. printf("%s", s1); [CS208marmot] 4. printf("%d", k); [-42] 5. printf("%p", &k); [0x40] 6. printf("%p", pointers[1]); [0x5] 7. printf("%s", pointers[2]); [kat] 8. printf("%c", *pointers[0]); [b] ======== #include int main() { int k = -42; char *address_of_k = (char *)&k; // print each byte of k, starting with the first byte in memory for (int j = 0; j < 4; j++) { char byte = *address_of_k; printf("0x%x\n", byte & 0xff); address_of_k = address_of_k + 1; } return 0; } ======== + Exam prep - In-class exam, Friday, October 6 - In Leighton 402 as usual - Closed-everything-except-your-brain (no calculator, no notes) - General topics - data representation - C - My philosophy of in-class exams - Stuff that I want you to have in your head, not just your notes - Mostly "what" and "how", only a little bit of "why" - No tricks - I try not to make it long (occasionally, I screw this up, but mostly not) - I indicate what I think is most important via classroom topics, homework assignments, sample programs, and the quiz - What to study - homework assignments - quiz - sample code - class notes - backup reference material as needed: textbook readings - Types of questions - Short answers - Here's some code; what's the output? - Write this tiny amount of code to do X (never more than 3-4 lines) - That memory grid from the quiz - Wildcard (I reserve the right to come up with a different type of question, but see philosophy above) - Integers - binary/decimal/hexadecimal notation - two's complement - byte order (little-endian vs. big-endian) - Characters - difference between characters and C char - codepoints vs. encodings - ASCII (chart will be provided) - UTF-8 encoding (chart will be provided) - UTF-16 BE and UTF-16 LE - [General C advice] - You can write your own experimental programs to see what happens when you do this or that - C types - int vs. long - char *p vs. char p[10] - string literals: "Hello" - char literals: 'A', '\0', '\\', '\'' - sizeof (don't confuse with strlen!) - C I/O (input/output) - printf, %c, %s, %d, %x, %X, %p - [not on exam] fgets (including what if line is longer than buffer?) - Null-terminated char strings - strlen - strcpy vs. strncpy (including what if source is longer than buffer in strncpy) - strcmp - printf %s vs. %p - C pointers - & as unary "address-of" operator - * in type declarations - * as unary operator for dereferencing - assignment statements with pointers - C bitwise operators - ~ (not) - & (and) - | (or) - ^ (exclusive or, also known as xor) - C stuff that's pretty much the same as Java - if, else - &&, ||, ! - while, for - {}, () - +, -, / (int div), % - function signatures + Questions: bits, quiz, exam, whatever