One, constant
1. What is a constant
Constant, which represents some fixed data
2. integer constant (int) and floating-point constant (float/double)
Floating-point constants are divided into double and float two data types
* Double: dual-precision floating point, in fact, is a decimal. such as 5.43,-2.3,0.0, etc.
* float: single-precision floating-point type, also decimal, is less accurate than double , meaning that it can represent a smaller number of decimal places. In order to differentiate from double,float type data is terminated with F , such as 5.43f,-2.3f,0.0f .
3. Character constants
* Enclose a number (0~9), an English letter (a~z,a~z),or other symbols in single quotation marks. This is what constitutes a character constant. such as '6',' A ',' & ', etc.
Note: single quotes can only be extended to 1 characters, and cannot be Chinese characters.
4. String constants
Enclose one or more characters in double quotation marks (""), which make up a string constant, such as "6"," male ".
Second, the variable
1. What is a variable
When the value of a data needs to be changed frequently, it should be represented by a variable when it gets indeterminate. Like game credits.
2. defining variables
1> Purpose
* Any variables must be defined before they can be used.
* The purpose of defining variables is to allocate a piece of storage space in memory to variables, which makes it easy to store data later.
* If more than one variable is defined, each of these variables will be allocated a different storage space
2> format
Variable type variable name;
such as int num;
* variable name belongs to identifier
* Variable type
* different types of variables occupy different sizes of storage space
* data types stored by constraint variables (easy operation)
3> examples
int Main () { int i; Char C; int A, B; return 0 ;}
3. Use of variables
1> assigned value
i = ten;
2> Modify
* variable values can be modified and assigned multiple times.
Ten;
* output values of one or more variables using printf
int Ten One ;p rintf ("a =%d, c =%d", A, c);
3> value passing between variables
* The value of one variable can be assigned to another variable
int Ten ; int B = A;
* Continuous Assignment
A = b = ten;
Three, memory analysis of variables
1. byte and address
1> memory in " bytes "
0x indicates hexadecimal.
2> The bytes occupied by different types are not the same, the larger the data, the more bytes are required
2. Storage of Variables
1> bytes Consumed is related to the type of the compiler environment
2> variable Instances
int Ten ; int ;
* memory is addressed by large to small, prioritizing bytes with large memory addresses to variables. b has a larger memory address than a
* each variable has an address: the address of the first byte is the address of the variable.
3> View memory address:
int a;printf ("A's address is:%p\n", &a);
4> Note
Do not attempt to use the value of a variable before it is initialized
int a;printf ("A's value is:%d\n"// not recommended
Four,scanf function
1. Introduction
2. Simple usage
int age;scanf ("%d", &age);
* The scanf function waits for the user's keyboard input and does not execute the code backwards.
3. Note
do not include \ n in the first parameter of scanf , such as scanf ("%d\n", &a); This causes the scanf function to not end
Five,sizeof
1. role
used to calculate the number of bytes of memory for a variable or a constant, a data type
2. Basic Form
* sizeof(variable \ constant)
* sizeof(data type)
Vi. break and continue
1. break
* application:switch\ cycle structure
* Break under loop nesting
2. Continue
* application: Cycle structure
* continue nested under cyclic nesting
04-Constants, variables, scanf functions, and sizeof