当前位置:网站首页>First acquaintance with C language (1)
First acquaintance with C language (1)
2022-07-27 02:17:00 【First seen in winter】

Hello everyone , I first met Yu Dong .
【 Statement 】: Because the author's record level is limited , Mistakes will inevitably appear in future blog posts , Readers are expected to criticize and put forward your valuable opinions , Looking forward to your comments .
List of articles
Preface
Basic understanding C Basic knowledge of language , Yes C Have a general understanding of language .
One 、C What is language ?
C Language is a general computer programming language , Widely used in the underlying development .C The design goal of the language is to provide a way to compile 、 Processing low-level memory 、 Generate a small amount of machine code and a programming language that can run without any support of the running environment .
Application field : Application software ( Baidu SkyDrive /QQ)、 operating system (win/linux)、 Driving layer, etc
C The origin of language : With the development of machine language , Binary cannot meet the increasingly complex work requirements . There is a mnemonic derived from binary . This gave birth to assembly language , And then it happened B Language , Finally, it forms what we use today C Language .
C Common compilers for languages are :Clang、GCC、WIN-TC、SUBLIME、MSVC、Turbo C etc. .
Two 、 first C Language program
1. How to use vs2019
Tips : As a beginner , Bloggers want to recommend you to use vs2019 This software ! Really super friendly to Xiaobai !
Recommended reasons : You can prompt your errors in time when writing , And support many practical shortcuts !
I don't say much nonsense , On dry !
① open vs2019, Click to create a new project .

② Create a new project

③ Configure new projects

④ Create new item

⑤ establish C Language source file

2. Programming
#include<stdio.h>
int main()
{
printf("hello word!\n");
return 0;
}
explain : This code means printing on the screen :hello word!
a. #include<stdio.h> It refers to the inclusion of header files .
b. <stdio> ------std( standard ) intput( Input ) output( Input ) It refers to standard input and output .
c. <.h>------header( The header file )
d.main It means main function ( It's the entrance to the program , There is and only one )
e. int For integer ( The return type of the function : integer ——> Corresponding (return 0;))
f. " " Enclosed is called string .
g. printf It's a library function , The use of library functions is to include header files ——> <stdio.h>
h. \n Means line break .
Be careful :C The habit of language is that the return value is 0 Yes means normal return , The return value is not 0 Indicates abnormal return .
Share vs2019 Use tips :
Click the line of code you want to copy (ctrl+c), And then use (ctrl+v) Paste directly .
(ctrl+k+c) For comment (ctrl+k+u) uncomment (Fn+F10) debug
(home) Jump to the beginning of the line (end) Jump to the end of the line
3、 ... and 、 data type
| data type | name | length ( byte ) |
|---|---|---|
| Character | char | 1 |
| Short | short | 2 |
| integer | int | 4 |
| Long integer | long | 4 |
| Longer integers | long long | 8 |
| Single-precision floating-point | float | 4 |
| Double precision floating point | double | 8 |
Common storage unit of computer
8bit=1byte
1KB=1024byte
1MB=1024KB
1GB=1024MB
1TB=1024GB
1PB=1024TB
notes : Type is to create variables
example :int age=20;
float weight=55.6;( here 55.6 The default is double type )
float weight=55.6f;( This is the case float type )
Four 、 Variable . Constant
Some values in life are constant ( such as : PI , Gender , Id card number , Blood type and so on )
And some values are variable ( such as : Age 、 weight 、 Salary )
Constant value ,C The concept of constant is used in language to express , Variable value C In language, variables are used to represent .
① How to define variables
int age=22;
float weight=45.5f;
char ch='f';② Variable name
- Only letters ( Including uppercase and lowercase )、 Numbers and underscores (_) form
- Cannot start with a number
- The length cannot exceed 63 character
- Variable names are case sensitive
- Variable names cannot use keywords
③ Classification of variables
- local variable
- Global variables
#include<stdio.h>
int global=2022;// Global variables
int main()
{
int local=2020;// local variable
int global=2021;// local variable
printf("global=%d\n",global);
printf("local=%d\n",local);
return 0;
}summary :
Outside the braces are global variables , Internal are local variables
expand :
Local variables outside braces global There is no problem with variables ! But when the local variable and the global variable have the same name , Local variables take precedence
Use of variables
#include<stdio.h>
int main()
{
int num1=0;
int num2=0;
int num3=0;
printf(" Please enter two numbers :");
scanf("%d %d" &sum1,&sum2);
sum3=sum1+sum2;
printf("sum3=%d\n,sum3");
return 0;
}notes :printf Enter a statement for ,scanf For the output statement .
④ The scope and life cycle of variables
Scope
Scope (scope) It's a programming concept , Generally speaking , The names used in a piece of program code are not always valid ( Usable ) The scope of the code that defines the usability of the name is the scope of the name .
1. The scope of a local variable is the local scope of the variable .
2. The scope of global variables is the whole project ( Other projects in the project can also be accessed )
Life cycle
The life cycle of a variable is the period between the creation of a variable and its destruction
- 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
C The definition forms of constants and variables of language are different
C Language constants are divided into the following
- Literal constants
- const Modified constant variable
- #define Defined identifier constant
- Enumeration constants
#include<stdio.h>
// give an example
enum Sex
{
MALE,
FEMALE,
SECRET
};
// In brackets MALE,FEMALE,SECRET It's an enumeration constant
int main()
{
// Literal constants demonstrate
3.14;// Literal constants
500;// Literal constants
//const Modified constant variable
const float pai=3.14f;// there pai yes const Modified constant variable
pai=5.14;// It can't be modified directly
//#define Demonstration of identifier constants
#define MAX 100
printf("max=%d\n",MAX);
// Enumeration constants demonstrate
printf("%d\n,"MALE);
printf("%d\n,"FEMALE);
printf("%d\n,"SECRET);
// notes : The default of enumerating variables is from 0 Start , Descending in turn
return 0;
}notes :
In the above example pai go by the name of const Modified constant variable ,const The modified constant is C In language, it is only the grammatical level that restricts the variable beat from being directly changed , however pai The essence is a variable , So it's called a constant variable .
summary
The above is the initial stage I summarized for you C Language dry goods , If there are mistakes, welcome baozi to criticize and correct in the comment area ! I also hope the knowledge I summarized can bring you harvest !
边栏推荐
- lvs+keepalived项目实战
- 选择器的使用语法与场景以及背景图片大小、文字盒子阴影、过度效果的使用方法
- HCIA Basics (1)
- [详解C语言]一文带你认识C语言,让你醍醐灌顶
- 7.8 Ruijie online written examination
- Autojs learning - realize image cutting
- The basic configuration of static routing (planning of IP address and configuration of static routing) realizes the accessibility of the whole network.
- 初识C语言(1)
- (CF1691D) Max GEQ Sum
- (超详尽版,不懂随时评论)Codeforces Round #804 (Div. 2)C The Third Problem
猜你喜欢

OSPF在MGRE环境下的实验

Timer interrupt experiment

Dynamic routing rip protocol experiment
![[explain C language in detail] takes you to play with functions](/img/44/53cdac9b9cf0d3f77e5da05956c3dc.png)
[explain C language in detail] takes you to play with functions

机械硬盘选购指南——从选购经历谈起

C语言实现小游戏【三子棋】注释详细 逻辑清晰 快来看看吧!!

HCIA动态路由OSPF实验

【数据库课程设计】SQLServer数据库课程设计(学生宿舍管理),课设报告+源码+数据库关系图

Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)

TIM输出比较——PWM
随机推荐
Lora通信应用开发
Republishing and routing strategy of OSPF
Unity Huatuo example project source code analysis and inspiration
Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
CAN总线通信应用
CF 1333C Eugene and an array
npm报错, Error: EPERM: operation not permitted, mkdir
2022zui新抖音24小时循环值守直播监控(一)直播间开播监控
OSPF在MGRE环境下的实验
TCP's three handshakes and four waves (brief introduction)
ACM mode input and output exercise
Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
Self introduction and planning about programming
Text to image intensive reading of paper gr-gan: gradually refine text to image generation
2022 open source work of the latest text generated image research (papers with code)
Unity Huatuo hot update environment installation and sample project
HCIA Basics (1)
[详解C语言]一文带你玩转循环结构(for_while_do-while)
C语言——二维数组、指针
Explain exi interrupt through the counting experiment of infrared sensor