当前位置:网站首页>The place where the dream begins ---- first knowing C language
The place where the dream begins ---- first knowing C language
2022-07-19 02:59:00 【Xiaotian who studies hard】
Catalog
Two 、 First time to know C Language
3、 ... and 、 Conclusion
Preface
Hello!!! I'm here again , From today on, we should start from scratch c The language , If you want to learn together, start .

One 、c What is language ?
C Language is a language Process oriented Of 、 Abstraction The general programming language of , Widely used in Bottom development .C Language can be in a simple way compile 、 Dealing with low grade Memory .C Language produces only a small amount of machine language And no need Running environment Support an efficient programming language that can run . Even though C Many low-level processing languages are provided function , But still keep Cross platform Characteristics of , Written in a standard specification C Language programs can include similar Embedded processor as well as supercomputer And many other operating platforms Computer platforms on compile .
ODA understands :
C Language is a language ( Analogy to Chinese 、 English 、 French, etc ), It's just ( chinese 、 English 、 French, etc ) It is used for communication between people , and c Language is a kind of language that people communicate with machines , There are many kinds of languages like this (Java、C++、Python etc. )
Why from C Language begins to learn ?
- Study c Language enables us to see the essence through the phenomenon (c Language is relatively close to other high-level languages Bottom ), It helps to learn other languages better in the future .
- C All living things , Many high-level languages are based on c Based on .
- C Language is omnipotent (C: I can do whatever you can , What I can do, you may not be able )
- C Language has a long history , Distinguished itself ( Such an old language can still rank in the top three --- Think of it as powerful , Learn quickly ).
Two 、 First time to know C Language
1. Print hello world
The code is as follows ( Example ):
#include<stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
- # For preprocessing instructions , Process before the program starts compiling
- stdio.h--- Standard input and output , In this program printf This function
- main() Function is also called the main function, which is where the program starts , A function can only have one main() function
- printf The function is contained in the header file stdio.h in , Role is to " " Between things printed on the screen
- return 0 Return to digital 0( stay C Languages often return 0 Return to normal , Return non 0 Returns... For an exception ), And main() Before int( Receive the return value of the function ) Echo each other
2. data type

Now let's look at the following :
char Character data type Store characters
short Short
int integer Store integer
long Long integer
long long long long
float Single precision floating point Store decimals
double Double precision floating point
What are the differences between these data types ?
The code is as follows ( Example ):
#include<stdio.h> int main() { printf("%d\n", sizeof(char)); printf("%d\n", sizeof(short )); printf("%d\n", sizeof(int )); printf("%d\n", sizeof(long )); printf("%d\n", sizeof(long long )); printf("%d\n", sizeof(float )); printf("%d\n", sizeof(double )); return 0; }
sizeof Used to view the size they can store ( Company : byte )
1byte( byte )= 8bit( The bit )
1kb = 1024 byte
1mb =1024 kb
1gb = 1024 mb
It can be seen that these types have different sizes , Different storage capabilities .
Why create so many data types ?
such as char、int、short、long、long long These types can be used long long To express ,float、double Both can be used. double To express , Why create so many types ?
We know ,C Language is a language that attaches great importance to efficiency , first-class C Programmers should use less resources , Complete the work with better efficiency . For example , Suppose you need a variable when programming , This variable represents a range from 0 To 100 Changing integer . Of course , At this time, any integer type is used (cha r, shortint, long int etc. ) Fine . however , The best way is to use char type , Because there is no sign char Type can represent from 0 To 255 The integer of , That's enough . Use other integers , Although it can also complete the work , But it wastes some space .
Maybe you said , My computer has a lot of storage space , Don't care about this little space . however , If the whole large-scale project does not pay attention to these , The wasted space is worth noting . Besides , Different types of data , The efficiency of computer use is also different . about C language , It is also a sentence , The computer may have to explain it in many sentences .
3. Constants and variables
In life :
Constant : ID number , Gender , Birthday and so on
Variable : height , weight , Vision, etc
Because programming is to solve problems in life , There are constants and variables in life , It's in C There is also... In the language .
C In language :
Constant : The amount whose value cannot be changed while the program is running . Constants do not occupy memory .
Variable : The amount by which the value of a program can change while it is running . The function of variables is to store data .
Definition of variables
Type name + Variable name
type + Variable name = The number
Recommend the following , It is a good programming habit to assign values to variables when creating them ( If you don't know what value to assign, assign 0)
for example :int a = 10;
char c = 'z';
double d =56.89;
Variable life cycle and scope
- Life cycle : The time period from variable creation to destruction
- Scope : Code range of variable availability ( Where it can be used, it is the scope )
Variables are divided into local variables and global variables
The scope of a local variable : The local scope of the variable ( The nearest to it {})
Scope of global variables : The whole project
The life cycle of a local variable : Enter the scope lifecycle begins , Out of scope life cycle ends
The life cycle of global variables : Whole procedure
The local variable is out of its scope , End of life cycle ( Be destroyed )
The scope of global variables is the whole program ( It's not destroyed until the end of the program )

Conclusion
There are only two truths in the world :1、 People are bound to die .
2、 The program must have Bug.
Thank you for watching !!!
边栏推荐
猜你喜欢

Win10 下OneDrive 失效重装

1. Introduction, analysis and implementation of asynctool framework

SSH Remote Control and access

Rhce8 Study Guide Chapter 7 service management

HCIA_ Rip experiment

Summary of the most complete methods of string interception in Oracle

RHCE8学习指南第一章 安装RHEL8.4

Yum warehouse service and PXE automatic deployment system

Configure VLAN and use OSPF protocol for layer 3 switches

二进制安装kubernetes 1.24.1
随机推荐
ncnn Allocator内存分配器
Oracle获取最后一条,第一条数据(按时间获取第一条和最后一条数据)
BiSeNetV2-面部分割
人脸关键点检测
审视自己投资的路
Shell script for, while loop statements, price guessing games
ENSP static routing experiment
MySQL数据库中的事务和存储引擎
Changes of service account in kubernetes1.24
【单片机仿真】(七)寻址方式 — 位寻址
全虚拟化与半虚拟化
5、AsyncTool框架竟然有缺陷?
Unicast、Multicast、Broadcast
Elk log analysis system
Rhce8 Study Guide Chapter 7 service management
【单片机仿真】(十六)控制转移类指令 — 无条件转移指令、条件转移指令
使用gatekeeper限制kubernetes创建特定类型的资源
【单片机仿真】(二十)ORG — 设置起始地址
Detailed explanation of case when usage of SQL
【Redis】什么是渐进式rehash



