Summary Programming Problem Solving and Abstraction with C - Terminologies and their use PDF

Title Summary Programming Problem Solving and Abstraction with C - Terminologies and their use
Course Engineering Computation
Institution University of Melbourne
Pages 7
File Size 188.6 KB
File Type PDF
Total Downloads 151
Total Views 296

Summary

COMPLec True = 1 False = 0 EX: X=1Y=Any non zero value (+1, -1, +57, -57..) is true, only zero is taken as false EX: If x = 0 (false) and y = 1 (true), then x && y = 0 (false) negative  negative times a positive is stillX==Y is 0 X!=Y is 1 i += 1 is the same as writing i = i...


Description

COMP20005 Lec05 True = 1 False = 0 EX: X=1 Y=2 Any non zero value (+1, -1, +57, -57…etc) is true, only zero is taken as false EX: If x = 0 (false) and y = 1 (true), then x && y = 0 (false)  negative times a positive is still negative

X==Y is 0

X!=Y is 1

i += 1 is the same as writing i = i+1 if x = 0 (false) then, !x = 1 (true) Operators work right to lef IF Statements: if (guard) Statement 1 OR For more than one statement line you need curly brackets, if (guard) { Statement 1 Statement 2 } also…. if (guard) { Statement 1

else (guard) { Statement 2 } } Lec07 For complicated numbers like 10-6 use #define EX: #define

TEN_POWER_SIX

1e-6

The biggest value an “int” can take on is 2000000 (2 billion) ** DO NOT PUT A SEMI COLON AT THE END OF A #DEFINE LINE Lec08 For loops have the format: for (initialize; guard; update) statement a for loop is used when you know how many times the loop will go around. Lec09 While loops have the format: while (guard) statement EX: int x; x=1 while (x output.txt getchar The function getchar gets any single character (letters, spaces etc) and brings it back and stores it in an int. The only thing that will stop it is when it comes to the end of the file (EOF). putchar The function putchar takes the character value and puts it to the output stream. Chapter 2.2 Constants: (values that don’t change throughout the program) #define CONSTANT 10 /* no semi colon at the end of the line*/ Types: Integer  int x;   

Can only store up to 2 billion No decimal point or exponent Uses %d

Double  double x; -

Can hold a larger range of values, although less accurate Contain decimal points or an exponent Uses %f or %lf (for reading) Exponents can are also doubles (use %e)

** %23.20f means at least 23 character positions should be used with 20 places afer the decimal. Leading blank characters are put if the value is less than the character positions identified. A (-) sign places the characters to the lef of the field (putting blank spaces on the right). Float  float x; -

The least precise type Can store the largest range Used in large arrays Uses %f

** make sure to use constants of the TYPE that match the variables they are being combined with EX: double x, y, z; y = (1/2) x + z /*the “1/2” is an “int” value and returns zero since y is a double*/ Special Characters  char ‘a’; -

Use character constants (EX: ‘\n’, ‘\t’, ‘\\’) Identified by single quotes Uses %c

Chapter 2.3 Operators and Expressions: ** In order to round properly from a double to an integer you must add 0.5 or vice versa

Operator Precedence: ** The assignment operator “=” works from lef to right EX: n=m=p=q=0 assigns all four variables the value “0” Chapter 3.2 An if function can be combined with a scanf to make sure data is being read correctly. Putting in the function exit with a call to EXIT_FAILURE can make your program exit if there is an error. Chapter 3.3 x > y > z is treated as (x > y) > z where (x > y) gives a true or false value of 1 or 0, therefore removing any assigned values from x and y.

Chapter 4.5 Type “control-D” into a window to indicate the program that no more input will be provided. Chapter 5.1 Functions: At the beginning of a program, a functions type must be declared before it is used. To use your own file function in a program you write: #include “func.c” - Use #include “func.h” to include a prototype For files that aren’t your own you write: #include Chapter 5.5 Recursive Functions: -

Recursive functions make calls to themselves.

Chapter 6.1 EXIT_FAILURE and EXIT_SUCCESS return the values 1 and 0 respectively, and can only be used when #include is stated.

Return just exits the current function where exit exits the entire program no matter how many layers of functions you are in. Chapter 6.4 Global variables: **DON”T USE GLOBAL VARIABLES Chapter 6.5 Static Variables: **AVOID USE IN RECURSIVE FUCNTIONS Chapter 7 Arrays: ** an array name is just a pointer to the first element in that array EX: x is a pointer to the beginning of the array x[ ] -

A double asterix ** is a pointer to a pointer Difference between array of characters and string, string has a null byte at the end.

2D Arrays: -

Y[ROWS][COLUMNS]

** Note int A[N], *p; /* This means *p is an int */ p=A; /* p is a pointer to an int, and so *p is assigned the first int in array “A” */ **Note char variable is 1 byte pointer variable is 8 bytes int variable is 4 bytes Structures:

-

We CAN’T test equalities on structures (p1 == p2) We CAN make a copy of one structure to another (p1 = p3)...


Similar Free PDFs