Basic
Head Part
1 2
| #include <stdio.h> // from system #include "xx.h"
|
Loops
For loops
Usage:
1 2 3 4
| for (init; condition; increment) { ... }
|
Tips:
- In “init” part, remember to create a new variable.
- Start with
0, use i<n to loop n times.
While loops and do-while loops
Usage:
1 2 3 4 5 6 7 8 9
| while(condition) { ... }
do { ... } while (condition);
|
Array
To create an array
Initialization
- You could initialize the elements partly: when elements provided is less than those in the array, only former elements were assigned.
- You could only assign elements one by one even assigning same value:
1
| int a[10]= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
- Not providing the length is allowed:
1 2 3
| int a[]={1,2,3,4,5}; int a[5]={1,2,3,4,5};
|
Pointer
Click for more about pointer in c
Struct
Click for more about struct in c