当前位置:网站首页>Take you to learn C step by step (second)
Take you to learn C step by step (second)
2022-07-24 07:07:00 【Wang Honghua x】
Catalog
One 、 Write a program
C There must be only one main function in the code of language , namely main function
The standard format is as follows :( Other writing methods are not recommended )
int main()
{
return 0;
}Note that all symbols are English characters .
What is a function ?
Let's briefly introduce some knowledge of functions :
We can compare a function to a factory , When we have a need , For example, we want to drink coke , Then we need a soda factory , The factory goes through a series of processing , Finally, make coke and give it to us , Sometimes we need to provide some raw materials to the factory .
main Is the name of the function , It is equivalent to the name of the factory . Add a pair of brackets at the end () Indicates that it is a function , namely main() It means a function ;
int For integer , This means that the function will return an integer data after execution ; It's like the word "soda" in a soda factory , After working in the factory , It will produce soda for us .
{ } Represents the body of the function , The program will follow { } The statements in the are executed step by step ; This is equivalent to how to produce soda water inside the factory .
return 0; Is the statement at the end of the function , It means to return an integer number 0, With the beginning int echo . That is to say, the factory finished and returned the soda , If there is no such statement , It's equivalent to working in a factory but not giving you soda !
Now just have a brief look , More on that later .
Next, we try to output something on the screen :
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}The result of the program execution is to print on the screen Hello world! And move the cursor to the next line , That is, I will change my line , Press ctrl + F5 Ready to run program .
Let's analyze this program again :
First let's look at ,printf(); There is () prove printf It's a function , The function of this function is to print on the screen “ ” Contents of Li . It's like you go to a printing factory , You should give others the content to be printed . This content , Just put it in ( ) in . So where does this function come from ?
stay C In language , Using any function requires declaration 、 Definition . Some functions are universal , Classify them into files ,printf This function is put in stdio.h In this header file . Now let's go back to the first line :
#include <stdio.h> Means to put the contents of this header file into this code . So we can use it printf Function !
as for Hello world! hinder \n We'll talk about it later , Here we only know that it means line feed .
If your computer presses ctrl + F5 It doesn't work , Then try pressing ctrl + FN + F5; Or as shown in the figure below :

Two 、 data type
To represent all kinds of data in life ,C Language provides three basic data types , Here's the picture :

So why do you put integer 、 Floating point types are divided into so many types ?
before this , We first need to know how much memory these types occupy , Although the above figure has been listed , But you can still verify it yourself :
#include <stdio.h>
int main()
{
printf("%d\n", sizeof(char)); //1
printf("%d\n", sizeof(short)); //2
printf("%d\n", sizeof(int)); //4
printf("%d\n", sizeof(long)); //4
printf("%d\n", sizeof(long long));//8
printf("%d\n", sizeof(float)); //4
printf("%d\n", sizeof(double)); //8
return 0;
}There's a little bit of caution here :sizeof Although the following is added ( ) , But it's not a function , It's an operator , image + - * / The same operator .
sizeof You can calculate the size of its contents , Unit is byte . What is the concept of byte ?
The smallest unit in a computer is bit - bits , Only one can be stored 0/1;
byte - byte ,1 byte = 8 bit, Can express 0 - 2^8-1, namely 0-255 common 256 Number ;
1 kb = 2^10 byte;
1 mb = 2^10 kb;
1 gb = 2^10 mb;
1 tb = 2^10 gb;
1 pb = 2^10 tb;
% Is to format the output ,%d Is output in integer form .
When the types are rich enough , We can be more flexible when using , Increase memory utilization .
So how to use types ?
If I need to store a person's age 20; Then where to deposit ? It must be memory , We need to apply for a space from the memory to store our data , The format is as follows :
int age = 20;
Means to apply for a piece of memory int Type of space , I call this space age, What's in it is 20.
If you want to store a person's height 1.65, Namely double high = 1.65;
All right. , This article ends here , If there are any questions , You can leave a message or a private message in the comment area , I promise I will read every one carefully , Reply earnestly . As for the more detailed content , such as floa t and double The difference between , We'll talk about it later , Now it's about putting C Know everything about language , Give you any code , You can understand .
The next article will talk about variables and constants .
边栏推荐
- STM32 ADC based on Hal library uses DMA multi-channel sampling and solves the problems encountered
- Prediction of advertising investment and sales based on regression analysis -- K neighborhood, decision tree, random forest, linear regression, ridge regression
- MySql的DDL和DML和DQL的基本语法
- 8. Use the quadratic geometry technology to draw a small column on the screen.
- Redis 分片集群
- SparkSQL核心使用,220724,
- Input some data and find the maximum output. (keyboard and file reading)
- 三级分类/菜单的查询——树形结构
- Redis special data type hyperloglog
- MySql的DDL和DML和DQL的基本语法
猜你喜欢

"Big factory interview" JVM Chapter 21 questions and answers

重磅直播 | ORB-SLAM3系列代码讲解地图点(专题二)

《大厂面试》之JVM篇21问与答

Can you increase muscle without exercise??? Just get an injection of hibernating black bear serum

济南人社已签1W+电子劳动合同,法大大助力HR数字化

tensorflow einsum函数

The function of extern, static, register, volatile keywords in C language; Nanny level teaching!

MySQL gets the self incrementing line mark (different from MySQL version)

Metaltc5.0 realizes webrtc version IPC of Junzheng pure C

STM32外部中断(寄存器版本)
随机推荐
"Big factory interview" JVM Chapter 21 questions and answers
Redis fragment cluster
chm文件打开时提示乱码
SparkSQL核心使用,220724,
第一部分—C语言基础篇_11. 综合项目-贪吃蛇
tensorflow scatter_ Nd function
C语言中extern,static, register,volatile 关键字的作用;保姆级教学!
You don't have to waste your life on others' standards
在线问题反馈模块实战(十二):实现图片删除功能
Wix path with spaces
An AI plays 41 games, and the comprehensive performance score of Google's latest multi game decision transformer is twice that of dqn
MGR_ mysqlsh_ Keepalive high availability architecture deployment document
(笔记整理未完成)【图论:求单源最短路径】
PyTorch 深度学习实践 第10讲/作业(Basic CNN)
【学习笔记】网页出现白屏可能的原因与优化方法
9. Use grid technology to draw a Pentagon on the screen.
Thinking of data analysis -- analyzing the retail industry as a whole -- an all-round and multifaceted detailed analysis
5. Template cache. Drawing a square can only move within the triangle
MySql的DDL和DML和DQL的基本语法
Processing tree structured data