Professional Documents
Culture Documents
Malcolm Wilson
Variables
Types int, char, double, long. NO type
for string see later.
unsigned above.
assignment
X=2 ;
C=v;
Keywords
C has a small number of keywords
http://tigcc.ticalc.org/doc/keywords.h
tml
Standard I/O
printf()
scanf()
Format specifiers %d, %f, %c, %s
http://en.wikipedia.org/wiki/Printf
http://en.wikipedia.org/wiki/Scanf
Operations
+, -, *, /, %, ^
Operation dependent on variable
type
Try some
Boolean
Any value other than zero is true.
Watch out for == is equal to.
Control
for(i=0, i<9, i++)
{ code block}
while (x<8)
{code block}
if (y==2)
{code block}
elseif(y==7)
{code block}
else
{code block}
Control
switch( myvar)
case 1 :
{code block
break;}
case 2:
{code block
break;}
default
{code block}
http://msdn.microsoft.com/en-us/library/66k51h7a
%28VS.80%29.aspx
Control
Code block is surrounded by {} if more
than one line. Dont need {} if code one
line long.
eg for(i=0; i<5; i++)
printf( number is: %d /n, i);
Preprocessor directives
#include
localfile
<standard_locations> /usr/include
#define
#define WIDTH 80
#define LENGTH ( WIDTH + 10 )
#defineu8unsigned char
int myarray[5];
int myarray[5]={1, 2, 3};
int myarray[]={1,2,3,4,5};
char mychararray=malcolm;
A string is a null terminated char
array.
Structures
struct struct_name {
structure_member;
...
} instance_1,instance_2 instance_n;
OR
struct struct_name
instance_1,instance_2 ,instance3
After defining the structure.
http://cprogramminglanguage.net/cstructure.aspx
Structures
Using typedef to avoid struct structurename all the
time.
typedef struct{
unsigned int house_number;
char street_name[50];
int zip_code;
char country[50];
} address;
address billing_addr;
address shipping_addr;
Pointers
Declared as using *
int *p says p in a pointer to an
integer.
p points to the memory location
where a integer is stored.
Confusing , in the code. *p means
the contents of memory location p.
And &p is the memory address of p.
sizeof()
Used for malloc to allocate memory
Boo Boos in C
Forgetting the semicolon
Using = in a boolean expression
instead of ==.
Completing a loop with no code
being executed.
while(test);
{ code block}
Deep C
Lvalues, Rvalues
Inline functions
Pointers to functions
Pointers to pointers and
multidimensional arrays.