Edmund J. Sutcliffe
Thoughtful Solutions, Creatively Implemented and Communicated
Edmund's ANSI C Quick Reference -
1
2
3
Click here for a printable version of this page.
Program
Structure/Functions
type fnc(type1,: : : ) function declarations type name external variable declarations main() { main routine
declarations local variable declarations statements }
type fnc(arg1,...) { function defnition declarations local variable declarations statements return value; } /* */ comments main (int argc, char *argv[]) main with arguments exit (arg) terminate execution
C Preprocessor
include library file #include <filename>
include user file #include "filename"
replacement text #define name text
replacement macro #define name(var) text
Example: #define max(A,B) ((A)>(B) ? (A) : (B))
undefined #undef name
quoted string in replace #
concatenate args and rescan ##
conditional execution #if, #else, #elif, #endif
is name defined or not? #ifdef, #ifundef
name defined? defined(name)
line continuation character \
Data
Types/Declarations
charater (1 byte) char
integer int
float (single precission) float
float (double precission) double
short (16 bit integer) short
long (32 bit integer) long
positive and negative signed
only positive unsigned
pointer to int, float, .. *int, *float, ...
enumeration constant enum
constant (unchanging) value const
declare external variable extern
register variable register
local to source file static
no value void
structure struct
create name by data type typedef typename
size of an object (type is size_t) sizeof (type)
Initialising
initialize variable type name=value
initialize array type name[]={value 1,... }
initialize char string char name[]="string"
Constants
long (suffix) L or l
float (suffix) F or f
exponential form e
octal (prefix zero) 0
hexadecimal (prefix) 0x or 0X
character constant (char) 'a'
char constant (oct) '\ooo'
char constant (hex) '\xhh'
newline, cr, tab, backspace \n, \r, \t, \b
special characters \\, \?, \', \"
string constants (ends with '\0') "abc...de"
Pointers,
Arrays & Structures
declare pointer to type type *name declare function returning pointer to type
type *f()
declare pointer to function returning type
type (*pf)()
generic pointer type void *
null pointer NULL
object pointed to by pointer *pointer
address of object name &name
array name[dim]
multi-dim array name[dim1][dim2]...
Structures
struct tag { structure template
declarations
};
create structure struct tag name
member of structure from template name.member
member of pointed to structure pointer -> member
Example. (*p).x and p->x are the same
single value, multiple type structure union
bit held with b bits member : b
ANSI
Standard Libraries
<assert.h> <ctype.h> <errno.h> <float.h> <limits.h>
<locale.h> <math.h> <setjmp.h> <signal.h> <stdarg.h>
<stddef.h> <stdio.h> <stdlib.h> <string.h> <time.h>
Character
Class Tests <ctype.h>
alphanumeric? isalnum(c)
alphabetic? isalpha(c)
control character? iscntrl(c)
decimal digit? isdigit(c)
printing character (not incl space)? isgraph(c)
lower case letter? islower(c)
printing character (incl space)? isprint(c)
printing char except space, letter, digit? ispunct(c)
space, formfeed, newline, cr, tab, vtab? isspace(c)
upper case letter? isupper(c)
hexadecimal digit? isxdigit(c)
convert to lower case? tolower(c)
convert to upper case? toupper(c)
|