当前位置:网站首页>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 !
边栏推荐
- JS 99 multiplication table
- [volatile principle] volatile principle
- [详解C语言]一文带你玩转函数
- 7.8 锐捷网络笔试
- Mechanical hard disk Selection Guide -- from the selection experience
- Codeforces Round #810 (Div. 2), problem: (B) Party
- 6.29 Zhong'an Summer Internship
- C语言实现小游戏【三子棋】注释详细 逻辑清晰 快来看看吧!!
- 关于编程的自我介绍和规划
- Codeforces Round #796 (Div. 2), problem: (1688C) Manipulating History
猜你喜欢

C语言——赋值运算符、复合的赋值运算符、自增自减运算符、逗号运算符、条件运算符、goto语句、注释

Test and open basic daily question brushing (continuous updating...)

C语言——数据类型、基本数据类型的取值范围
![[explain C language in detail] this article takes you to know C language and makes you impressed](/img/37/205c1c6eb2ba704941e48ff89c6268.png)
[explain C language in detail] this article takes you to know C language and makes you impressed

2022最新直播监控24小时监控(三)直播间弹幕解析

通过对射式红外传感器计次实验讲解EXTI中断

7.7 sheen Xiyin written test

C语言——while语句、dowhile语句、for循环和循环结构、break语句和continue语句

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

静态路由综合实验
随机推荐
通过对射式红外传感器计次实验讲解EXTI中断
HCIA静态路由综合实验
6.30 written examination of MediaTek
MySQL课程1.简单命令行--简单记录 欢迎补充纠错
静态路由缺省路由vlan实验
[explain C language in detail] takes you to play with functions
【数据库课程设计】SQLServer数据库课程设计(学生宿舍管理),课设报告+源码+数据库关系图
Beyond hidden display ellipsis
Golang - sync包的使用 (WaitGroup, Once, Mutex, RWMutex, Cond, Pool, Map)
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (II)
[Database Course Design] SQLSERVER database course design (student dormitory management), course design report + source code + database diagram
TIM输出比较——PWM
JS logical operator
Lecture 3 - GPIO input / output library function usage and related routines
C语言——第一个程序、打印、变量和常量
Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
2022最新抖音直播监控(二)直播间流媒体下载
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (I)
RIP V2 的简单应用(v2的配置、宣告、手工汇总、RIPV2的认证、沉默接口、加快收敛)
MySQL课程2.表的各种查询