Úvod Jazyk C

C language
Code example
<stdio.h> # include / * insert a header file * /
char letter = 'A'; / * 8-bit transformation of the letter * /
main () / * main function of the program * /
{
printf ( "Hello first program \ n"); / * functions from the stdio.h library * /
}
Operators
Arithmetic operands
* - Multiplication
/ - Division (integer)
% - Remainder (integer)
+ - Addition
- - Subtraction
+ + - Increment by 1 (Pos)
- - Decrement by 1 (Pos)
Logical operands
== Equality comparison
! = Compare inequality
& & Logical product
| | Logical sum
! Negation
<Less than
<= Less than or equal
> Greater than
> = Greater than or equal
Commands
If – else
For
While
Do
Switch
If-else
Command to deal with conditions.
if (logical_ expression) command _1; else command_2;
Or too:
if (logical_ expression)
{
command _1;
command _2;
}
else
}
command _3;
command _4;
}
For
For for the order is known by the number of passages
for (strart_ expression; end_ expression, iteration_ expression)
command;
Better:
for (strart_ expression; end_ expression, iteration_ expression)
{
command _1;
command _2;
}
While
While is a cycle while the condition at the beginning
while (expression) command;
Better:
while (expression)
{
command _1;
command _2;
}
Do
Do is a cycle while the condition at the end
do
{
Commands
}
while (expression);
Switch
switch (expression)
{
case constant_1: command _1; break;
case constant _2: command _2; break;
...
case constant _N: command _N; break;
default: command _def; break;
}
Function - procedures
Procedures in C should be treated as functions with no return value data type called
void.
Each function must be declared and defined.
Declaration - is only the return value function, its name and its parameters
Definitions - it also contains the entire block of commands performed
Writing functions:
returned_type function_name (parameter_list_function)
(
body (ie commands) functions
return returned_value;
)
Directives
Directives control the progress of the translation. Beginning with "# The parts are:
# include <> - used when compiling the file, it will search function
# define name value - define not just numerical constants
# pragma - special directive used primarily in the software development for
microcontrollers