Points of C

Basic

Head Part

1
2
#include <stdio.h> // from system
#include "xx.h" // from current folder

Loops

For loops

Usage:

1
2
3
4
for (init; condition; increment)
{
...
}

Tips:

  1. In “init” part, remember to create a new variable.
  2. 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

1
int a[4];

Initialization

  1. You could initialize the elements partly: when elements provided is less than those in the array, only former elements were assigned.
1
int a[10]= {0, 1, 2};
  1. 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};
  1. Not providing the length is allowed:
1
2
3
// these two are equal
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