(a), today we have to learn the main include the content:
1. Symbol concept and its naming principle
In c language, symbolic constants, variables, arrays, functions, etc. all need a certain name, we call this name an identifier.
Identifier partitioning: Key words, predefined identifiers, and user identifiers
Naming rules:
(1), consisting only of letters, numbers, underscores, or dollar signs ($)
(2), cannot start with a number
(3), cannot be the same name as the key word
(4), strictly case-sensitive
Naming conventions:
(1), a meaningful name (e.g. user name: UserName)
(2), hump name (if a name has more than one word, the first letter lowercase other words first uppercase, or the first letter of each word uppercase)
must be a letter, number, underscore, and cannot start with a number, the identifier name should not be the same as the keyword
2. Introduction and use of annotations in C language
(1),//double slash comment, also known as a single-line comment can comment a line and commented code does not participate in compiler compilation, that is, the compiler encountered a code block with comments
Will skip directly over
(2),/**/Multi-line comments, such as:/* I am the content of the comment, the program executes directly skip this part of the content * *
3. Data and data types
What is a data type:
We are always dealing with data in our life, such as our age, height, weight, videos, documents, music, etc., which we see everywhere in our daily life.
Can be called data, the computer defines different data types in order to store these different data.
Unit of measurement of the data:
1 B (byte byte) =8 bit (bit)
1 KB (KByte) =1024 B
1 mb=1014 KB
1 gb= MB
1 tb= 1014 GB
The types of data commonly used in the C language are:
4. Memory consumption and range of data type
The data type uses byte descriptions such as:
What we need to know here is that Mac computers are 64-bit after 10.7, which means we need to remember that the Mac 10.7 version of the computer after Char occupies
Bytes are 1 bytes, int, float type occupies 4 bytes, double type occupies 8 bytes, short type occupies 2 bytes, long, long long, and void
It's all 8 bytes of space.
ranges represented by different types
5. Overview and classification of constants and methods of representation
C language has a rich data type, in the development, generally use constants or variables to represent these data types, "volume" represents data. Constant, it means that some fixed
Data, that is, data that cannot be changed. such as the date of birth of a person, social security number.
Constant classification:
(1), integer constant, that is, the integer constant.
Binary (for example: 0b0001)
Octal (for example: 0123)
Decimal (for example: 100)
Hex (for example: 0x123)
(2), real-type constants
Single-precision (e.g.: 2.3f)
Double precision (e.g. ' a ')
(3), character type constant
Normal characters
Escape Character
(4), string constants, note that string constants and character constants are not the same
(5), string constants
Enclosed in double quotes, it can be a character, a number, a symbol (for example: "Abd", "a", "* * *").
(6), a special character constant (escape character) such as:
6. Concept and definition of variables
(1), definition (declaration)
Format 1: Variable type variable name;
For example: int A; float B; Char ch;
Format 2: Variable type variable name, variable name;
For example: int A, B;
(2), the specification of variable naming
Strict adherence to the naming principle of identifiers
Variable names should be as much as possible to understand the text, concise
The name of the variable should be named according to the Hump (follow the naming convention)
7 , initialization of variables and references
(1), the initialization of variables
int a=10; int a=10,b=20,c=30;
int a=10; int &b; A=b;
8 , the scope of the variable
(1), C language, all variables have their own scope, declaring the type of the variable is not, its scope is different, C language variables can be divided into two categories in the scope,
a is a local change volume, one is global variable.
According to the C language, local variables: variables defined inside a method are called local variables; global variables: variables defined outside the method are called global variables. Local
Variables and Global Variables The main difference is that they have different life cycles.
The lifetime of a global variable: statically allocated memory, which resides in memory until the program runs.
The lifetime of a local variable: dynamically allocating memory on the thread stack.
In addition, the scope of global variables and local variables is different, for example, the scope of variables in the class in the current class, the scope of variables in the class method in the current method
Usage scenarios for global variables: Multiple places to use, everyone to share.
Usage scenarios for local variables: used only in the current location.
To make a clearer distinction between local variables and global variables, let's look at the segment code, such as:
9. Why do variables distinguish between types
(1), in order to more reasonable use of memory, different data types need to store the space is not the same
(2), data storage format is not the same, int 4 bytes, float 4 bytes, double 8 bytes
(3), different data types they may not operate the same way.
10. printf function Introduction and common usage
The printf function is a standard library function that represents the print content to the console, and the scanf function is a pair, scanf is the content that receives the user input into the program
The printf function is called in the following format:
printf ("Format control string", output item list), such as printf ("Hello world\n");
%MD Problem (set field width or number of digits) m is a number that can be positive or negative
printf ("%md", 10); For example, m=5, the printed value is: 10 (of which 10 before three spaces), if 5 will be after 10 to fill three spaces.
printf ("%0MD", 10); For example m=5, print out is 00010;
11,%f output accuracy problem
For single-precision numbers, when using the%f format character output, only the first 7 digits are valid digits, and the decimal 6 bits.
For double-precision numbers, when using the%LF format character output, the first 16 digits are valid digits, and the decimal 6 bits.
12, scanf function Introduction and use
The scanf function is also a standard library of functions
scanf ("Format control string", enter a list of items); such as scanf ("%d,%d", 5,10);
13, SACNF use precautions
The SCANF function prototype is included in the standard input output header file "Stdio.h" for receiving keyboard input content
Format: scanf ("Format control string", entry address list);
int a=0; scanf ("%d", &a); Defines a variable a of type int to receive the value entered by the user.
14, scanf function principle
When the user enters the content, the user input is stored in the scanf input buffer, and the scanf function is based on the character requirements of the format control, from the input
The buffer is taken sequentially what it wants. if the content obtained from the buffer is consistent with my formatting requirements, the values are stored in the variable, and if the format is inconsistent,
do not modify the value of a variable (for example: int a=10, but when we type input is a, then the last printed value will be 10, if the scanf buffer
There is also content, then scanf will not prompt us to enter again.
iOS Development Learning Record the 4th day of C language learning