C Reference Cheat Sheet Page 4

ADVERTISEMENT

C Reference Cheat Sheet
by
Ashlyn Black
via
Pointers (cont)
Arrays (cont)
They can also have an incomplete type. Operators other
Same as name[​ i nt].
void *v;
*(name + int)
than assignment cannot be applied as the length of the type
Elements are contiguously numbered ascending from 0.
is unknown.
Memory address of element int in
&name[int]
A data structure pointer.
struct
array name.
type *y;
Same as &​ n am​ e [i​ n t].
name + int
An array/​ s tring name can be used as a pointer to the first
type
array element.
Elements are stored in contiguous memory.
z[];
Measuring
Accessing
Returns length of array. (Unsafe)
sizeof(array) /
A memory address.
x
sizeof(arrayType)
Value stored at that address.
*x
Returns length of array. (Safe)
sizeof(array) /
Value stored in structure pointer y member a.
y->a
sizeof(array[0])
Memory address of normal variable varName.
&varName
Dereferencing a void pointer as a type pointer.
Strings
*(type
*)v
'A' character
Single quotes.
A pointer is a variable that holds a memory location.
"AB" string
Double quotes.
Null termin​ a tor.
\0
Arrays
Strings are char arrays.
Decl​ a ring
char name[4] = "Ash";
You set array length.
type name[int];
is equivalent to
You set array length and initialise
type name[int] = {x,
elements.
char name[4] = {'A', 's', 'h', '\0'};
y, z};
int i; for(i = 0; name[i]; i++){}
You set array length and initialise all
type name[int] = {x};
elements to x.
\0 evaluates as false.
Compiler sets array length based on initial
type name[] = {x, y,
Strings must include a char element for \0.
elements.
z};
Size cannot be changed after declaration.
Escape Characters
Dimensions
alarm (bell/beep)
backspace
\a
\b
One dimension array.
name[int]
formfeed
newline
\f
\n
Two dimens​ i onal array.
name[int][int]
carriage return
horizontal tab
\r
\t
Accessing
vertical tab
backslash
\v
\\
Value of element int in array name.
name[int]
single quote
double quote
\'
\"
question mark
\?
Any octal ANSI character code.
\nnn
Any hexadecimal ANSI character code.
\xhh
By Ashlyn Black
Published 28th January, 2015.
Sponsored by
Last updated 20th April, 2015.
Measure your website readability!
Page 4 of 13.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education