Pointers and Structures are critical part of C.
Use strcpy
to assig string.
switch, for, while, do-while, goto, break, continue
char
is int
type but only got 8bit, which is smaller than int
.
C does not allow to define a function inside another function.
Split functions into different source code file.
There is no ;
in #define
Use header files to store definitions.
static
will limit the global variables inside the source code file scope. This means that internal static variables provide private, permanent storage within a single function.
register
tells the compiler that the variable will be used heavily.
COnditional Inclusion is used in the pre-processor to have dynamic definition.
pointers are variables.
*ptr
is value the it points to, &value
is the pointer (location).
Unary operators, such as ++, *, &
, associate right to left.
By default C passes arguments to function by value.
The array name is like a pointer, but array name is not a variable! See example:
pa = &a[0];
pa = a; // the name of the array is the pointer to the first element'
// a[i] => *(a+i)
// a++ is not legal, while pa++ is legal.
// char s[] and char *s is equivalent.
/* month_name: return name of n-th month */
char *month_name(int n)
{
static char *name[] = {
"Illegal month",
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
};
return (n < 1 || n > 12) ? name[0] : name[n];
}
int (*comp)(void *, void *);
/* comp is a pointer to a function that has two void * arguments and returns an int. */
Idiom way to push/pop for stack
*p++ = val;
val = *--p;
while (*s++ == *t++);
if (!*s) return 0;
Pointers to Pointers
Pointers to Functions
int (*comp) (void *, void *)
: comp is a pointer to a function accepts two args and return an int.
int *comp ()
: comp is a function that returns a pointer to an int.
A structure is a collection of one or more variables, possibly different types, grouped together under a single name.
A struct
declaration defines a type. For example, struct point
type.
Access member of structure.
p->x // if p is a pointer to a structure
p.x // if p is a structure
The structure operator, .
and ->
, together with ()
and []
are at the top of the precedence hierarchy and bind very tightly.
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing