Introduction to C Programming Class Page

C code.    C code run.    Run code run.

ANSI C Keywords
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while

"When you can snatch the error from the code it will be time to leave"--Master Programmer


Extended Keywords
asm
_cs
_ds
_es
_ss
cdel
far
huge
interrupt
near
pascal

"After three days without programming, life becomes meaningless." -- Master Programmer


Arithemetic Operators
Operator
Action
-
Subtraction
+
Addition
*
Multiplication
/
Division
%
Modulus (gives the division remainder)
--
Decrement (x=x-1)
++
Increment (x=x+1)
=
Assignment (a=b, makes a the same valve as b) 

"When program is being tested, it is too late to make design changes." -- Master Programmer


Relational and Logical Operators
Operator
Action
>
Greater Than
>=
Greater Than or Equal To
<
Less Than
<=
Less Than or Equal To
= =
Equals 
&&
Logical AND
||
(double pipe) Logical OR
!
Logical NOT

"A well-written program is its own heaven; a poorly-written program is its own hell." -- Master Programmer


 Basic Data Types
Type
Approx Size in Bits
Range
char
8
-127 to 127
int
16
-32,767 to 32,767
float
32
Six digits of percision
double
64
Ten digits of percision

"Though a program be but three lines long, someday it will have to be maintained." --Master Programmer


Data Type Modifiers
Modifier
Used on
Approx Size in Bits
Range
signed
char
8
-127 to 127
 
int
16
-32,767 to 32,767
 
unsigned
char
8
0 to 255
 
int
16
0 to 65,535
 
short
int
16
-32,767 to -32,767
       
long
int
32
-2,147,483,647 to 2,147,843,647
 
double
128
Ten digits of percision

"Let the programmer be many and the managers few -- then all will be productive." -- Master Programmer


Conversion Characters (Format Specifiers) used with printf( ) and scanf( )
Code
printf("%c", ch)
scanf("%d", &num)
scanf("%s", s1)
Format
%c
*
*
Character
%d
*
*
Integer
%i
*
*
Integer
%e
*
*
Scientific Notation lowercase e
%E
*
  Scientific Notatation uppercase E
%f
*
*
Float Point Decimal
%o
*
*
Octal Integers
%s
*
*
String of Characters
%u
*
*
Unsigned Decimal Integers
%x
*
*
Hexidecimal Integers lowercase letters
%X
*
  Hexidecimal Integers uppercase letters
%p
*
*
Displays a pointer (memory address)
%%
*
  Prints a % sign

"Without the wind, the grass does not move. Without software, hardware is useless." -- Master Programmer

Escape Sequences
\a
Alarm
\b
Backspace
\f
Form Feed
\n
Newline
\r
Carriage Return
\t
Tab
\v
Vertical Tab
\0
Null
\'
Single Quote
\"
Double Quote
\\
Backslash

"Programming in BASIC causes brain deterioration" -- Master Programmer


Commonly Used functions
Function
Header File
Operation
printf ( )
stdio.h
Prints to screen
scanf( )
stdio.h
Reads from Keyboard
getchar( )
conio.h
Reads char from keyboard; waits for return keystroke
getch( )
conio.h
Reads char from keyboard; does not wait for return keystoke
gets( )
conio.h
Reads string from keyboard
puts( )
conio.h
Writes string to screen
strcat( char* str1, char* str2)
string.h
Combines s1 and s2
strcmp(const char* s1, const char* s2)
string.h
Compares s1 to s2
strcpy(char* s1, const char* s2)
string.h
Copies s2 into s1
strlen(char* s1)
string.h
Returns length of s1
tolower(int ch)
ctype.h
Returns lowercase of ch
toupper(int ch)
ctype.h
Returns uppercase of ch
sqrt(double num)
math.h
Returns the square root of num
pow(double base, double exp)
math.h
Returns base raised to the exp power
rand( )
stdlib.h
Returns a random number

"It is time for you to leave." -- Master Programmer

Quotes are from the TAO of Programming and other sources