当前位置:网站首页>001 basic knowledge (unfinished)
001 basic knowledge (unfinished)
2022-06-30 15:02:00 【Shadow_ shape】
Catalog
const Modified constant variable
# define Defined identifier constant
Characters and strings ( A character array )
Photo Article ( Convenient for mobile phone viewing )
Basic data types
Data types are used to define variables
char Character data type
short Short
int integer
long Long integer
long long Longer integers
float Single-precision floating-point
double Double precision floating point
sizeof Data type size
sizeof yes C A key word of language , Calculate the size of the data type , Unit is byte
sizeof(char) 1
sizeof(short) 2
sizeof(int) 4
sizeof(long) 4
sizeof(long long) 8
sizeof(float) 4
sizeof(double) 8
A byte is 8 position , Each can represent 0 and 1 Two figures
Variable
Used to describe data that can be changed
Create variables
When creating variables, it's best to initialize
char ch = ‘a’; The variable type is char, The name is ch, The content is a character a
int age = 18;
float pi = 3.1415926;
classification
Variables are divided into global variables and local variables
Global variables { } Curly braces are used to define
local variable { } Curly braces are used to define
When local variables and global names conflict , Local variables take precedence
for example :
#include <stdio.h>
int a = 100;
int main(void)
{
int a = 10;
printf(“%d”, a);
return 0
}
The screen printing result of the program is 10
Scope
Local variable scope : The local scope of the variable , That is, inside the current brace
Global variable scope : The whole project
Life cycle
The life cycle of a variable is the period between the creation of a variable and its destruction
1. The life cycle of a local variable is : Enter the scope lifecycle begins , Out of scope life cycle ends .
2. The life cycle of global variables is : The whole life cycle of the program .
Constant
Describe immutable data
Literal constants
3.14
10
'a'
"abcde"
const Modified constant variable
const int num = 10; //num It's a constant variable -- Has constant properties ( Properties that cannot be changed )
num = 20; // This is the wrong statement , The statement is in the VS2022 Direct error reporting in ,num Do not modify the
printf("%d", num);
int arr[10] = { 0 };
const int n = 10; //n The essence is still a variable , It just has constant properties ,n The value of cannot be modified
int arr2[n] = { 0 }; // This is the wrong statement ,n It's a constant variable
# define Defined identifier constant
# define M 200 //M It's a constant , The value is 200
M = 100; // The statement is incorrect ,M It's a constant , You can't change it like this
printf("M = %d\n", M);
Enumeration constants
Constants that can be enumerated one by one
enum Date
{
DAY1 = 1,// Assign initial value to 1, The default is 0
DAY2 = 3,// Assign initial value to 3
DAY3,// There is no initial value , Its value is the above value +1, That is to say 4
DAY4,
DAY5
};
enum Date day1 = DAY1;
//DAY1 = 1// The statement is incorrect ,DAY1 Is a constant
printf("%d ", day1);//1
printf("%d ", DAY2);//3
printf("%d ", DAY3);//4
printf("%d ", DAY4);//5
printf("%d ", DAY5);//6
Characters and strings ( A character array )
character
The characters are enclosed in single quotes
'a'
'b'
'c'
character string
A string is a string of characters , In double quotation marks , The end of a string is a \0 The escape character of .
"abcdef";
"123456";
A character array
The string hides a... At the end \0 The characters of
char arr1[ ] = "hehe";
char arr2[ ] = {'a', 'b', 'c'}; // error , Should be changed to char arr2[] = {'a', 'b', 'c', '\0'};
printf("%s\n", arr1); // Print hehe
printf("%s\n", arr2); // Print out garbled code , because arr2 No, \0
String length
When calculating the length of a string \0 It's the end sign , It doesn't count as string content .
printf("%d\n", strlen("haha")); // Print 4
printf("%d\n", strlen(arr1));
printf("%d\n", strlen(arr2)); // Print garbled code , I don't know where the string ends
Photo Article ( Convenient for mobile phone viewing )
边栏推荐
- How to realize selective screen recording for EV screen recording
- Binary rotation array (1)
- Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
- catkin_ Make reports an error, transfers the location of the workspace, and uses other people's workspace files to cause compilation errors
- Greedy interval problem (5)
- G - navigation nightare
- JS array sorting method summary
- CCF image rotation (Full Score code + problem solving idea) 201503-01
- Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)
- How does hbuilder display in columns?
猜你喜欢
How to realize selective screen recording for EV screen recording
LIS error: this configuration section cannot be used in this path
Solve the problem that codeblocks20.03 on win11 cannot run for the first time
Detailed explanation of settimeout() and setinterval()
Clear the route cache in Vue
day02
CCF access control system (Full Score code + problem solving idea) 201412-1
CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3
PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
[extensive reading of papers] multimodal attribute extraction
随机推荐
Non decreasing column
How to get palindrome number in MATLAB (using fliplr function)
IO interview questions
分布式--OpenResty+lua+Redis
Double pointer circular linked list
CCF adjacent number pairs (Full Score code + problem solving ideas + skill summary) 201409-1
Binary rotation array (2)
1062 talent and virtue (25 points)
Basic learning notes of C language
Matlab finds a prime number that is greater than a given integer and follows this integer
1134: Legal C identifier query
Basic requirements for tool use in NC machining of vertical machining center
val_ Loss decreases first and then increases or does not decrease but only increases
Matlab finds prime numbers within 100
1136: password translation
@PathVariable
Computer screenshot how to cut the mouse in
Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)
L - Jungle roads (minimum spanning tree)
CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3