Week 3: understanding and using basic keyword

First, the key 32
1, data type
void-free type, a function return values, parameters, pointer
type unsigned signed integer instructions
char short int long integer type
float double float
struct union enum structure, union, enum
auto automatically created, destroyed
const constant
static variable static
register register
volatile volatile, unstable
extern variable or function declaration
typedef or redefine
the number of bytes sizeof
flow control
IF Switch Case BREAK the else default
for the while do Continue
GOTO return

2 , operators,
arithmetic operators: + - * /%
relational operators:> <> = <= = ==!
logical operators: && ||!
independent variable operators: + / -
assignment operator: = + = - = = * / = ...
? ternary operator: a b: c;
bitwise operators: & | ~ ^ << >>

3, the first program in any system can be normal operation (last week ponder the answer to question)

```c
hello world
#include <stdio.h>
int main(int argc,char const * argv[])
{
printf("hello world!\n");
return 0;
}
```

Second, the first C program
programmers write C code, not a standard, it needs to continue to be compiled for a standard can be translated into.
Responsible for the translation program called preprocessor directive called pre-translated instructions (starting with #), the translation process is called pretreatment.
gcc -E hello.c outputs the result of the preprocessing to the screen.
gcc -E hello.c -o hello.i pretreatment results saved to a file.

#include a file into the current file
<> search system according to the specified directory and file header loading
"" priority load from the current directory header file, if the system is no longer specified directory to search for and load the file header.

C language standards committee to C language provides some basic functions in a functional form, these functions are packaged in a standard library, libc.so.
standard input output


```c
#include <stdio.h>
```

C language file type classification:
.c source files, which record is the main function code.
.h file secondary source file for explaining what variables, functions, and they have the format of the source file.
After pretreatment .i file, by the .c into
.s file compiled by the .i into
.o object files by .s into the
.out executable files, merge into a plurality of .o .

`` C `
int main (int argc, char const * the argv [])
` ``

C language as a function of the smallest unit (segment having a feature code) for managing code (libraries, modules, files, functions)
main function is the entry function C language, there is one and only one, when you run the program will be "operating system" automatically invoked.
The return value type function name (parameter list)

`C
function body
return transactions;
`

 

argc, argv parameter is required when the main function is executed, provided by the operating system.
int represents the main execution there will be a return type int result to the caller (operating system) when finished.
return terminates the execution of the function, then the data is returned to the calling function are.
main function's return value:
0 means everything is normal
negative error appears
positive value represents an exception

`` C `
the printf (" Hello World \ n-! ");
` ``
the printf function is a standard library for the outgoing data.
Parameters: It requires two parameters portions (+ data format), the number of parameters may not be fixed.
Returns: the number of successful display of character
scanf is a function of the standard library for input.
Parameters: It requires two parameters portions (+ address format), the number of parameters may not be fixed.
Return Value: Enter the number of successful data
printf, scanf is used with a debugger, printf for the analog display data to the interface, scanf used to retrieve data from the analog interface.
\ n which is an escape character, the symbol can not be normally displayed.
\ n Enter
\ r return function similar to the first home key
\ b backspace function similar to the Backspace
\ rings A, for generating a warning
\\ output \
%%% output

Two, how the C code into executable programs
1, editor: using file editor such as vim coding
vim hello.c
2, pre-treatment: the compiled code programmer translated into standard C code.
gcc -E hello.c -o hello.i generates preprocessed file .i end
3, the compiler: the standard C code translated into assembly code.
gcc -S hello.i generated assembler files ending in .s
4, Assembly: to translate assembly file into an object file
gcc -c hello.s generates .o object files ending in
5, the link: the number of files into standard an executable file
gcc ao bo co produce an executable program, the default name is a.out
can set the name of the executable file by -o.
6, load: ./ a.out load the kernel from the hard disk

Three, GNU compiler
GNU is an open source organization responsible for maintaining the Linux kernel source code, GNU compiler compiler is GNU Linux systems specifically for the community and the development of a compiler.
The compiler is composed of many different functions of the program consisting of: preprocessor, compiler, linker, and so on.
gcc compiler commonly used parameters:
-E -S -c -o
-Wall more stringent standards to check the code
-Werror warning when the error-handling
-g adding debugging information, gdb
optimization level when compiling code -O
-D compiler when you define a macro
-std specify criteria to compile -std = gnu99

Fourth, the data type
why the data type classification?
To save storage space and improve the speed of calculation.
Built-:
Integer:
Signed: its highest bit binary used to represent positive and negative, this is called the sign bit.
127 -128 ~ char. 1 Signed
Signed Short 2 ~ 32767 -32768
Signed int. 4 ~ -2147483648 2147483647 (ten digits)
Signed Long ~ 4/8 -9223372036854775808 9223372036854775807 (nineteen bits)

Note: signed on behalf without added;
unsigned: all its bits are used to represent data.
255 ~ 0. 1 char unsigned
unsigned Short 65535 2 0 ~
unsigned int. 4 0 ~ 4294967295
unsigned Long 4/8 0 ~ 18446744073709551615 (twenty digits)

Note: When you define a data unsigned, unsigned essential, and the standard library (stdint.h) is convenient for us to use them to do redefined.
uin8_t, uint16_t, uint32_t, uint64_t
float:
single precision: float 4
Double: double 8
precision: long double 12/16
Note: floating-point data in memory to be represented scientific calculation, there is a special format, compared with integer calculation speed is relatively slow, there is no special requirement is not recommended.
Note: six significant decimal places.
How to determine whether the floating-point data is "zero value"
0.000001> f && f> -0.000001
self:
structure struct, union union, enum enum
simulation:
Character: So-called character is due to the pattern of pixels, the real memory is an integer in the store.
When the need to display the correspondence relationship according to character display ASCII symbol.
'0' 48
'A' 97
'A' 65
char display characters% C
Note: storing character which is an integer, to translate it into a computer character.
Boolean: There may be considered after the first C language and some Boolean type, C language is no Boolean type.
In stdbool.h code contains the header files, you can use Boolean type.
bool true false (value 4 bytes);

Fifth, the constant and variable
constants: the program can not be changed during operation data, literal constants, macros, constants, enumeration constants.
The default is int type 10
3.14 default type double
100u8 unsigned char
100u unsigned Short
100U unsigned int
100L unsigned Long
1.0f a float
1.0L Long double
variable: the data storage cartridge (container), need to define used.
Definition: data type variable name;
int NUM;
Note: The default value of the variable is uncertain, for safety to initialize it.
In fact, the definition of a variable is determined by the type of data to system memory blocks allocated to the variable name, but does not clean up this memory, the memory size.
Named rule variable name:
1, numbers, letters, underscores.
2, can not start with a number.
3, must be unique keywords.
4, the length should not exceed 30.
5, see the name EENOW (function, type, identity, range)
using:
is assigned: num = 10;
involved in computing: num * 100 + 300
input and output variables:
variables printf into the output:
printf type variable names
% hhd% D LD%% HD
% HHU% Hu LU% U%
the LF LF% F%%
% G does not show unnecessary zero

% digits after the decimal point is provided .nf
% setting data MD display width, fill spaces default
display width% 0 MD setting data, not complement 0
% -md set left alignment, the default fill spaces
printf either the output value of the variable, and You can enter some tips to improve the experience of the program.
Exercise 1: definition of the various types of variables and initializes,
using the value of the variable display printf.

Value of the input variables:
variables enter into the scanf:
Address scanf type of the variable (related with the pointer).
Note: variable name & address of the variable to get
attention: scanf except placeholder, everything else is not to increase, especially \ n Do not add.
Exercise 2: definition of the various types of variables, each of the input from the keyboard using scanf variable.
Then use printf to display the value of variables.

Guess you like

Origin www.cnblogs.com/wzt1/p/11968225.html