Trying to cram as much "knowledge" of C as possible on one page.
Clearly this will be the Reminder... and not the Beginner... page.
The book I'm working from (for the moment) is Red Hat Linux 6 Unleashed; David Pitts, Bill Ball, et. al.; Sams; 1st Printing, 1999; ISBN 0-672-31689-7.
See:
Contents
Introduction
- "Third-generation procedural describes computer languages that clearly distinguish the data used in a program from the actions performed on that data." First time I encountered that definition -- could be useful.
- The "unit" of a C program is the function -- every program must have
main()
- Declare:
int swapadmin( int *, int *);
- Define:
int swapadmin( int *a, int *b);
- Call:
lower = swapadmin(&i, &j);
- Two kinds of data manipulated in C programs:
- literals
- variables -- must be declared before use --
int i;
- Basic data types:
- integers
- floating-point (real) numbers
- characters
- arrays (no string -- use an array of characters
- No boolean true / false, but in conditional expressions, 0 is false, nonzero is true
- Pointers (pointers, and dereferencing, and .. oh no!) -- wordsmith these descriptions until they really mean something to me, and are easily interpreted
- & = dereference -- deal with the address of the data
- * = treat as a pointer -- deal with the value pointed at
Here's a little test program that seems worthy of understanding:
main()
{
int i;
int *ptr;
i=5;
ptr = &i;
printf("%d %x %d\n", i, ptr, *ptr);
}
- Complex data structures (structs)
struct typevar {type var1; type var2; type var3; ...}; followed by struct typevar structvar;
- Statements -- separated by semicolons
- Blocks -- statements surrounded by curly braces
- Expressions -- methods for combining values into new values
- comparison -- see lists below
- mathematical -- see lists below
- bitwise -- see lists below
- Loop Control Statements (one line versions, for now)
-
while (expression) statement
-
do statement while (expression);
-
for(expr1;expr2;expr3) statement, which can also be done by a while statement: expr1; while (expr2) {statement; expr3}
- Interrupting a loop:
- break -- terminates execution and exits loop
- continue -- terminates execution and continues loop with next item
- goto --
- Conditional Statements
-
if (expr) statement
-
if (expr) statement else statement
- switch / case -- get an example -- trying: =switch {expr} case val1: statement; case val2: statement; default statement;
- "ternary" if (??) --
((expr) ? val1 : val2)
- Macros (the third part of (pointers, and dereferencing, and macros, oh no!) — some examples:
Comparison Operators
- < -- less than
- > -- greater than
- == -- equal
- <= -- less than or equal
- >= -- greater than or equal
- || -- logical
or
- && -- logical
and
- ! -- logical
not
Mathematical Operators
Binary
- + -- add
- - -- subtract
- * -- multiply
- / -- divide
- % -- integer remainder (modulo??)
Unary
- - -- negate (??) (oops, I added this, assumed it existed -- it might not)
- ++ -- increment (x = x + 1)
- -- -- decrement (x = x - 1)
Bitwise Operators
- & -- bitwise
AND
- | -- bitwise
OR
- - -- negation (one's complement)
- << -- bit shift left
- >> -- bit shift right
Printing
printf(["<format_string>",] <comma_delimited_arguments>);
Format string options:
- %% -- percent sign
- %E, %e -- double in scientific notation
- %f -- double with decimal point
- %G, %g -- double -- format depends on value ?? (test)
- %X, %x -- hexadecimal with [capital, lowercase] letters
- %c -- single character
- %d, %i -- integer
- %ld -- long integer
- %n -- "count of charaters written in current printf"
- %o -- octal
- %p -- pointer (address or data??))
- %s -- "character pointer (string)"
- %u -- unsigned integer
Escape characters for strings:
- \"
- \'
- \?
- \ * \a -- (audible) bell
- \b -- backspace
- \f -- form feed (new page)
- \n -- newline
- \ooo -- octal number
- \r -- carriage return
- \t -- horizontal tab
- \v -- vertical tab
- \xhh -- hexadecimal number
Contributors
- () RandyKramer - 03 Apr 2003
- <If you edit this page: add your name here; move this to the next line; and include your comment marker (initials), if you have created one, in parenthesis before your WikiName.>
Page Ratings