“This is the second day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”
Recently, REVIEWED the C language, the author will be in nuggets synchronous update my review progress! First year C students and those who want to brush up on C /C++ should not miss it |
---|
✈ if there are mistakes, welcome bigwigs to criticize and correct! thank you |
Initial C language 01
1. Long long length specified in the C language standard
sizeof(long long) > =sizeof(long) > =sizeof(int)
Copy the code
2. Real is floating point
3. Units in a computer
Bit: bits byte: bytes1byte = 8bit
kb = 1024byte
mb = 1024 kb
gb = 1024mb
tb = 1024 gb
pb = 1024 tb
Copy the code
4. A project has only one main function
The same is true for multiple files
5. Local and global variables
Local variables – Variables defined inside curly braces (code blocks) are local variables
Global variables – Variables defined outside the braces are global variables
scope
Scope of a local variable: The scope of the local variable
Scope of global variables: this can be used throughout the project
The life cycle
1. The life cycle of the program is the same as that of the main function
2. Life cycle of local variables: the life cycle of local variables begins when entering the range of local variables and ends when leaving the range of local variables
3. Lifecycle of global variables: The lifecycle of the program
Literal constants
I’m just going to write it out
Such as:3.14
a
Copy the code
7. A constant variable modified by const
A variable that can’t be changed has a constant property, but it’s still a variable, it’s a constant
Example:
int n = 100;
int arr[n] ={0}; // error, [] must be a constant, write variable is a variable length array, C99 only supports variable length array concept
const int n = 100; //n is not a constant. N has a constant property and cannot be modified
int arr[n] = {0}; / / error,
Copy the code
8.#define defines the identifier constant
You define it as a real constant
Note: #define is not followed by a semicolon
#define Max 100
int main(a)
{
int a =Max;
int arr[Max] = {0}; // Correct, because #define defines Max as constant
printf("%d\n",a);
Max = 200; // Error Max is constant and cannot be modified
return 0;
}
Copy the code
9. The enumeration
Some things in life can be enumerated
Such as: gender: male, female, secret three colors: red, green and blue
enum Sex //enum SexIs an enumeration type {
// Possible values of enumeration -- Enumeration constants, which can be assigned, otherwise the first number starts at 0 and goes down +1
MALE,
FEMALE,
SECRET
}; // Note the semicolonNote: enumeration constants are followed by commas, not semicolons. The last enumeration constant may not be followed by a comma, but must be followed by a commaCopy the code
enum Sex
{
MALE,
FEMALE,
SECRET
};
int main(a)
{
enum Sex s = SECRET; //s is an enumeration variable whose value is the corresponding value of SECRET
s = 10; // The value of s can be changed.
// MALE = 4; //ERR Because MALE is a constant, it cannot be changed
// If the enumeration constant is not assigned, the default value starts at 0 and goes down +1
printf("%d\n", MALE); / / 0
printf("%d\n", FEMALE); / / 1
printf("%d\n", SECRET); / / 2
return 0;
}
Copy the code
enum Sex
{
MALE=3,
FEMALE=7,
SECRET
};
int main(a)
{
printf("%d\n", MALE); / / 3
printf("%d\n", FEMALE); / / 7
printf("%d\n", SECRET); //8 //SECRET is not assigned, and the value is +1 down FEMALE
return 0;
}
Copy the code
10. On variable-length arrays
C99
The compiler must support the C99 standard, or it will not run
Variable length arrays cannot be initialized
//c99
int n = 10;
int arr[n] = {0}; // Err variable length arrays cannot be initialized
int arr[n]; / / right
Copy the code
11. The string
The default at the end of the string is \0,
For arrays, the uninitialized part is automatically put \0
Today to this ~ hope to help you! You are welcome to click on this topic and subscribe! At the same time, welcome the bigwigs to criticize and correct!