C语句
if-else
If test evaluates to true, then then-statement is executed and else-statement is not.
If test evaluates to false, then else-statement is executed and then-statement is not. The else
clause is optional.
switch
The switch statement compares test to each of the compare expressions,
until it finds one that is equal to test.
Then, the statements following the successful case are executed.
All of the expressions compared must be of an integer type, and the compare-N expressions must be of a constant integer type (e.g., a literal integer or an expression built of literal integers).
Optionally, you can specify a default case. If test doesn’t match any of the specific cases listed prior to the default case, then the statements for the default case are executed.
Traditionally, the default case is put after the specific cases, but that isn’t required.
do-while
This example also prints the integers from zero through nine:
1 | int x = 0; |
A break statement can also cause a do loop to exit.
for
If you need to test two conditions, you will need to use the && operator:
1 | int x, y; |
A break statement can also cause a for loop to exit.
block
A block is a set of zero or more statements enclosed in braces. Blocks are also known as compound statements.
Often, a block is used as the body of an if statement or a loop
statement, to group statements together.
You can declare variables inside a block; such variables are local to that block.
In C89, declarations must occur before other statements, and so sometimes it is useful to introduce a block simply for this purpose:
label
A null statement is also sometimes used to follow a label that would otherwise be the last thing in a block.
The label can be anywhere in the same function as the goto statement that jumps to it,
but a goto statement cannot jump to a label in a different function.
break
If you put a break statement inside of a loop or switch statement which itself is inside of a loop or switch statement, the break only terminates the innermost loop or switch statement.
continue
You can use the continue statement in loops to terminate an iteration of the loop and
begin the next iteration.
void*
http://blog.chinaunix.net/uid-22197900-id-359211.html void* 用法
return
return-value is an optional expression to return.
If the function’s return type is void,
then it is invalid to return an expression.
You can, however, use the return statement without a return value.
If the function’s return type is not the same as the type of return-value, and automatic type conversion cannot be performed, then returning return-value is invalid.
If the function’s return type is not void and no return value is specified, then the return statement is valid unless the function is called in a context that requires a return value. For
example:
1 | x = cosine (y); |
Even in contexts where a return value is not required, it is a bad idea for a non-void function to omit the return value.
typedef
In the case of custom data types, you can use typedef to make a new name for the type while defining the type:
1 | typedef struct fish |
To make a type definition of an array,
you first provide the type of the element,
and then establish the number of elements at the end of the type definition:
1 | typedef char array_of_bytes [5]; |