当前位置:网站首页>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 )
边栏推荐
- Three ways and differences of defining functions in JS
- 1077 kuchiguse (20 points)
- Solve the problem that codeblocks20.03 on win11 cannot run for the first time
- Computer screenshot how to cut the mouse in
- Programming exercises: special numbers (problem solving ideas + code implementation)
- 1131: genetic correlation
- Maximum area of islands searched
- CCF access control system (Full Score code + problem solving idea) 201412-1
- Matlab calculates the factorial sum of the first n numbers (easy to understand)
- Sum of squares of two pointers
猜你喜欢

Clear the route cache in Vue

CCF window (Full Score code + problem solving idea) March 2, 2014

PS cutting height 1px, Y-axis tiling background image problem

Computer screenshot how to cut the mouse in

How does hbuilder display in columns?

CCF date calculation (Full Score code + skill summary) February 2, 2015

1 figure to explain the difference and connection between nodejs and JS

PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available

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
随机推荐
Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
Searching for single element in dichotomy
1025 pat ranking (25 points)
Programming of left-hand trapezoidal thread
Double pointer letter matching
2021-08-05 leetcode notes
Matlab judge palindrome number (only numbers)
K - or unblocked project (minimum spanning tree)
Hbuilder most commonly used and full shortcut key set
Shift operator (detailed)
IO interview questions
1133: output family and friends string
Examples of bubble sorting and matrix element screening in MATLAB
HD mechanical principle · classic dynamic drawing of mechanical design
The kth largest element in the sorted array
CCF Z-scan (full mark code + problem solving ideas) 201412-2
1076 forwards on Weibo (30 points)
Programming exercises: special numbers (problem solving ideas + code implementation)
这种零件该怎么编程加工?
Svn password forgetting solution