Ultimate Course Study Guide This package includes chapters: 5: Selection Statements 6: Loops 7: Basic types 8: Arrays 9: Functions 11: Pointers 12: Pointers and Arrays 13: Strings 16: Structures 17: Advanced Uses of Pointers 22: Input/Output.

23 Pages
Unlock Document

Chemical Engineering and Applied Chemistry
Amer Shalaby

APS106 COURSE REVIEW April 7, 2011 While statement, expression or condition that's evaluated is always at the beginning of the loop, so it is evaluated at the beginning The do statement, the loop is implemented first then the condition is evaluated, after the first iteration For statement, had three expressions, the first is the declaration and initialization of some sort of counter, the second is a condition that gets tested after each iteration, and the last is some update to the counter Nested loops, typically two levels, for each iteration of the outer loop you do al the iterations of the inner loops, you can even have a nested loop using while and do, or any combination of the three main method of implementing loops Jump statements: break, continue and "goto" alter the normal flow of the program control When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop Three components of a function: Return_type function_name (argument list) Return_type function_name (argument list) { Variable declarations Statements Return } Function call: how we invoke the function Arguments preceded by type and are separated by a comma if there is more than one Recursion in programming: is basically a function that calls itself, recursively. But it has to stop somewhere, so it reduces the problem, like a factorial, until it reaches its desired output. You need a base case for any recursive function. If the stopping case or the base case is reached -Solve the problem Else -Reduce the problem using recursion Arrays: general form is (type array_name [size]), accessing array elements (array_name [index] = element of array), the first element of an array has an index of 0 Pointers: declaring a pointer p to an int: int *p; Luigi La Corte 1 11-04-20 Accessing the content of a variable point to by p: *p The name of an array is its pointer Calling a function value vs. calling by reference P is a variable just like any other but it stores addresses, in this case, int variables. P points to int. hold addresses of integer variables To get the value of that variable, we use an asterisk to declare the value at p Just using an array name is a pointer to the address of the array The most powerful thing about pointers is that you can pass a value to a function it can change the values of the variables in main (), this is called calling by reference Pointer math: math is appropriate for the type of data stored at that address, adding 1 to an integer address adds 4 bytes, char addition by 1 adds 1 byte, double addition by 1 adds 8 bytes Character strings are fundamentally character arrays that end with a \0 Char A [ ] = hi there; Char *B = hi there; Hi there is stored as a string constant; its address is stored at the character pointer B There are two ways of created character strings as listed above. The first one is by creating a regular character sting (this is if you would want to convert each element into upper case then you would have to do this, the second is by pointer, but you would not be able to modify an element in the array An array needs to have a null character to be treated as a character array When you pass pointers to functions: some common errors are that people declare a pointer but don't initialize it in main, so it will give you weird things Before you start using a variable or a pointer with initializing you will get unexpected results A pointer must point to something that is defined We need n + 1 array elements to store a string of length n Structures: struct tag-name { Type element1; Type element2; Type element; } Variable-list; Either tag-name or variable-list is optional, but at least one must be present The programming process: 1. Analyze: understand the Problem 2. Design: plan the logic (sketch out a solution algorithm-should use pseudo code) 3. Code: write the computer program 4. Build: translate program into machine language Luigi La Corte 2 11-04-20 5. Test: try different input & verify the outputs Final exam Will consist of several questions each one having more than one part Different types of questions covered What is the output What is the problem with the given code What does the given code do Write a function Selected C libraries and function will be provided in the exam booklet (will be posted on the course website before the exam) Like Standard I/O, ctype.h, string.h, and their respective functions. Course topics type: Every expression has a type. This is a fundamental concept: you should know the type of every expression you write. Char, int, long, float, double, array, pointer, struct Assignment statement: lhs = rhs; 1) evaluate the expression on the right hand side; this produces a value 2) place that value in the variable on the left hand side Control flow: If/else; while, for (you should be able to use both, and rewrite either using the other) Array: A 0-based list of information all items have the same type each array has a length Pointer: Easy to screw up, and pointer errors can be very hard to track down Array variables can be used as pointers Pointer variables can be used as arrays String: String is our word for an array of chars that is terminated by \0 Which strings cant you
More Less

Related notes for APS106H1

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.