160 likes | 174 Views
Prepare for your C programming exam by reviewing key concepts such as pointers, linked lists, algorithm analysis, and basic Linux commands. Practice writing programs and answering short questions to ace your exam.
E N D
Exam Format • 100 Total Points • 50 Points Writing Programs • 25 Points Short Answer • 25 Points of Tracing Code • Similar to programming assignments and labs • All point values are approximations
Example Programming Problems • Given a 2D array of characters, write a short piece of code that will count the number of cells that are directly above the letter ‘Q’ and have the value ‘Y’. • Given a file of strings, write a program that will read each line into a linked list node such that the lines are in the correct order (insert at the end) and each insert is a O(1) operation. Then traverse the linked list and print out the lines to the screen.
Example Short Answer • Explain why traversing a linked list of nodes is an O(n) operation. • What is the order in Big O notiation of the following operation: The pop operation for a stack implemented as a linked list.
What will the EXACT output of the following program be? intfoo = 9; int *ptr = &foo; float foo2 = 5.7; *ptr = 2; foo2 = foo - foo2; if (foo > foo2) printf("Hello!\n“); else if (foo < foo2) printf(“%f\n”, foo2); else printf(“%d\n”, foo); printf(“\n”); printf (“foo2 is %f\n”, foo2);
Fundamentals of C • ?? Points • Declaration of variables and functions • Looping and conditional statements • While, for, if • One and two dimensional arrays • Simple I/O • Printf, scanf, fscanf, fgets • Strings and string functions • Understand the Code Camp and Game of Life programs
Pointers • 25 Points • A pointer is a variable that holds the address of a memory location • Declaration • int *ptr; • Assignment • ptr = &foo; //& is the address function • Dereferencing • *ptr = 54; //same as foo=54; • You can point to any kind of data type • Relationship between arrays and pointers • Understand the “malloc” and “free” commands • Returning a pointer from a function
Structures • 15 Points • Declaration • Assignment • Use of the “.” operator • Pointers to structures • (*ptr).field • ptr->field • Structures used in Linked Lists
Linked Lists • 20 Points • Declaring a linked list • Adding a node to a linked list • Removing a node from a linked list • Traversing a linked list • What is the order of magnitude of each of the above operations? • Understand the Stack312_ll code and the linked list code from class.
Stacks • 20 Points • Operations • makeStack • Push • Pop • isEmpty • isFull • Know how to use in a problem and implement • Understand the Stack Fun! assignment
Linux • 8 Points • Know the basic commands you needed to complete a program in Linux • Know how to edit a file in Linux • Know how to compile and run a C program in Linux • Know how to create directories and move around the Linux file system
Command Line arguments • 12 Points • Make sure you understand how to use argc and argv • Understand the use of atoi(char *)
Algorithm Analysis • 20 Points • Understand what Big O notation is • Be able to look at an algorithm or piece of code and determine how much work it has to do (and then the Big(O) analysis of the code) • Understand the relative speed of the Big O orders. • Which is faster? O(1) or O(n)
How to Study • Rewrite all the programs. • Don’t memorize C! Code syntax will be on the exam. • Learn by doing and recognizing patterns. • Don’t stay up late!! Get some sleep and eat a good breakfast.
What to bring • Pencils and erasers • We will provide scratch paper • No calculators