Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
C Reference Card

C Reference Card

Ratings: (0)|Views: 30|Likes:
Published by api-3709694
a concise 2 page reference of C programming language
a concise 2 page reference of C programming language

More info:

Published by: api-3709694 on Oct 14, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

C Reference Card (ANSI)
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 de\ufb01nition
declarations
local variable declarations
statements
returnvalue ;
}/* */
comments
main(int argc, char *argv[])
main with args
exit(arg )
terminate execution
C Preprocessor
include library \ufb01le
#include <\ufb01lename>
include user \ufb01le
#include "\ufb01lename"
replacement text
#definename text
replacement macro
#definename (var )text
Example.#define max(A,B) ((A)>(B) ? (A) : (B))
unde\ufb01ne
#undefname
quoted string in replace
#
concatenate args and rescan
##
conditional execution
#if, #else, #elif, #endif
isname de\ufb01ned, not de\ufb01ned?
#ifdef, #ifndef
namede\ufb01ned?
defined(name )
line continuation char
\
Data Types/Declarations
character (1 byte)
char
integer
int
\ufb02oat (single precision)
float
\ufb02oat (double precision)
double
short (16 bit integer)
short
long (32 bit integer)
long
positive and negative
signed
only positive
unsigned
pointer toint,float,. ..
*int, *float,. ..
enumeration constant
enum
constant (unchanging) value
const
declare external variable
extern
register variable
register
local to source \ufb01le
static
no value
void
structure
struct
create name by data type
typedeftype name
size of an object (type issize_t)
sizeofobject
size of a data type (type issize_t)
sizeof(type name )
Initialization
initialize variable
type name=value
initialize array
type name[]={value1,... }
initialize char string
charname []="string "
c
\ue0001999 Joseph H. Silverman Permissions on back. v1.3
Constants
long (su\ufb03x)
Lor l
\ufb02oat (su\ufb03x)
For f
exponential form
e
octal (pre\ufb01x zero)
0
hexadecimal (pre\ufb01x zero-ex)
0xor 0X
character constant (char, octal, hex)
'a', '\ooo', '\xhh'
newline, cr, tab, backspace
\n, \r, \t, \b
special characters
\\, \?, \', \"
string constant (ends with'\0')
"abc... de"
Pointers, Arrays & Structures
declare pointer totype
type*name

declare function returning pointer totype type*f()
declare pointer to function returningtype type(*pf)()
generic pointer type

void *
null pointer
NULL
object pointed to bypointer
*pointer
address of objectname
&name
array
name[dim]
multi-dim array
name[dim1][dim2]...
Structures
structtag {
structure template
declarations
declaration of members
};
create structure
structtag name
member of structure from template
name.member
member of pointed to structure
pointer-> member
Example.(*p).x andp->x are the same
single value, multiple type structure
union
bit \ufb01eld withb bits
member:b
Operators (grouped by precedence)
structure member operator
name.member
structure pointer
pointer->member
increment, decrement
++, --
plus, minus, logical not, bitwise not
+, -, !, ~
indirection via pointer, address of object*pointer, &name
cast expression to type
(type)expr
size of an object
sizeof
multiply, divide, modulus (remainder)
*, /, %
add, subtract
+, -
left, right shift [bit ops]
<<, >>
comparisons
>, >=, <, <=
comparisons
==, !=
bitwise and
&
bitwise exclusive or
^
bitwise or (incl)
|
logical and
&&
logical or
||
conditional expression
expr1? expr2: expr3
assignment operators
+=, -=, *=,...
expression evaluation separator
,
Unary operators, conditional expression and assignment oper-
ators group right to left; all others group left to right.
Flow of Control
statement terminator
;
block delimeters
{ }
exit fromswitch,while,do,for
break
next iteration ofwhile,do,for
continue
go to
gotolabel
label
label:
return value from function
returnexpr
Flow Constructions
ifstatement
if (expr)statement
else if (expr)statement
elsestatement
whilestatement
while (expr)
statement
forstatement
for (expr1;expr2;expr3)
statement
dostatement
do
statement
while(expr );
switchstatement
switch (expr) {

caseconst1 :statement1 break; caseconst2 :statement2 break; default:statement

}
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)
String Operations<string.h>
s,tare strings, cs,ctare constant strings
length ofs
strlen(s)
copyct tos
strcpy(s,ct)
up ton chars
strncpy(s,ct,n)
concatenatect afters
strcat(s,ct)
up ton chars
strncat(s,ct,n)
comparecs toct
strcmp(cs,ct)
only \ufb01rstn chars
strncmp(cs,ct,n)
pointer to \ufb01rstc incs
strchr(cs,c)
pointer to lastc incs
strrchr(cs,c)
copyn chars fromct tos
memcpy(s,ct,n)
copyn chars fromct tos (may overlap)memmove(s,ct,n)
comparen chars ofcs withct
memcmp(cs,ct,n)
pointer to \ufb01rstc in \ufb01rstn chars ofcs
memchr(cs,c,n)
putc into \ufb01rstn chars ofcs
memset(s,c,n)
1
2
3

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->