Add some more shit
This commit is contained in:
parent
cf9b87dc08
commit
a0e9a5e376
11 changed files with 102 additions and 7 deletions
73
c.md
73
c.md
|
@ -54,4 +54,75 @@ You can replace `gcc` with other compilers (e.g. `clang`, `tcc`, `g++` etc.), th
|
|||
- `-O3`: optimize for program speed, greatly speeds up your program (you can also use less aggressive `-O2` and `-O1`)
|
||||
- `-Os`: optimize for smaller program size
|
||||
- `-g`: include debug info, you want this so that debuggers can point to your source code
|
||||
- `-std=c99`: use the C99 standard
|
||||
- `-std=c99`: use the C99 standard
|
||||
|
||||
## Cheatsheet
|
||||
|
||||
It's pretty important you learn C, so here's a little cheat sheet for you.
|
||||
|
||||
**data types** (just some):
|
||||
|
||||
- **int**: signed integer, at least 16 bits (-32767 to 32767) but usually more
|
||||
- **unsigned int**: unsigned integer, at least 16 bit (0 to 65535) but usually more
|
||||
- **char**: smallest integer of at least 8 bits (1 byte, 256 values), besides others used for containing [ASCII](ascii.md) characters
|
||||
- **unsigned char**: like char but unsigned (0 to 255)
|
||||
- **float**: [floating point](float.md) number (usually 32 bit)
|
||||
- **double**: like float but higher precision (usually 64 bit)
|
||||
- **short**: smaller signed integer, at least 16 bits (−32767 to 32767)
|
||||
- **long**: bigger signed integer, at least 32 bits (-2147483647 to 2147483647)
|
||||
- **pointer**: memory address (size depends on platform), always tied to a specific type, e.g. a pointer to integer: `*int`, pointer to double: `*double` etc.
|
||||
- **array**: a sequence of values of some type, e.g. an array of 10 integers: `int[10]`
|
||||
- **struct**: structure of values of different types, e.g. `struct myStruct { int myInt; chat myChar; }`
|
||||
- note: header *stdint.h* contains fixed-width data types such as *uint32_t* etc.
|
||||
- note: there is no **string**, a string is an array of *char*s which must end with a value 0 (string terminator)
|
||||
- note: there is no real **bool** (actually it is in header *stdbool*), integers are used instead (0 = false, 1 = true)
|
||||
|
||||
**branching aka if-then-else**:
|
||||
|
||||
```
|
||||
if (CONDITION)
|
||||
{
|
||||
// do something here
|
||||
}
|
||||
else // optional
|
||||
{
|
||||
// do something else here
|
||||
}
|
||||
```
|
||||
|
||||
**for loop** (repeat given number of times):
|
||||
|
||||
```
|
||||
for (int i = 0; i < MAX; ++i)
|
||||
{
|
||||
// do something here, you can use i
|
||||
}
|
||||
```
|
||||
|
||||
**while loop** (repeat while CONDITION holds):
|
||||
|
||||
```
|
||||
while (CONDITION)
|
||||
{
|
||||
// do something here
|
||||
}
|
||||
```
|
||||
|
||||
**do while loop** (same as *while* but CONDITION at the end):
|
||||
|
||||
```
|
||||
do
|
||||
{
|
||||
// do something here
|
||||
} while (CONDITION);
|
||||
```
|
||||
|
||||
**function definition**:
|
||||
|
||||
```
|
||||
RETURN_TYPE myFunction (TYPE1 param1, TYPE2, param2, ...)
|
||||
{ // return type can be void
|
||||
// do something here
|
||||
}
|
||||
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue