当前位置:网站首页>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 .
边栏推荐
- STM32H750VBT6驱动程控增益放大模块PGA113——基于CubeMX的Hal库
- 【学习笔记】网页出现白屏可能的原因与优化方法
- Input some data and find the maximum output. (keyboard and file reading)
- 济南人社已签1W+电子劳动合同,法大大助力HR数字化
- [learning notes] Web page rendering process
- Jinan renshe has signed 1w+ electronic labor contract, which greatly helps HR digitalization
- Use the root user to create a new user and set the password for
- SparkSQL核心使用,220724,
- 你就是你,没有人可以取代
- [learning notes] what happens when the URL is input into the page presentation?
猜你喜欢

tensorflow einsum函数

Redis 持久化

Huawei experts' self statement: how to become an excellent engineer

Practice of online problem feedback module (12): realize image deletion function

GE口:SGMII模式和serdes模式

Prediction of advertising investment and sales based on regression analysis -- K neighborhood, decision tree, random forest, linear regression, ridge regression
![(note sorting is not completed) [graph theory: find the shortest path of single source]](/img/58/e61aea3c4d0a33d3615144763160f7.png)
(note sorting is not completed) [graph theory: find the shortest path of single source]

xavier_normal_ 初始化测试

Three level classification / menu query tree structure

Geek planet ByteDance one stop data governance solution and platform architecture
随机推荐
Design a function print to print the string. If only the string parameter s is passed, the string length is compared with 10, greater than 10, print the first 10 characters, less than 10, and output a
处理树形结构数据
Wix path with spaces
【学习笔记】url输入到页面展现中发生了什么?
Don't care too much about what others think of you
JMeter笔记2 | JMeter原理及测试计划要素
STM32H750VBT6驱动程控增益放大模块PGA113——基于CubeMX的Hal库
STM32外部中断(寄存器版本)
【学习笔记】网页出现白屏可能的原因与优化方法
(笔记整理未完成)【图论:求单源最短路径】
Ge port: sgmii mode and SerDes mode
Input some data and find the maximum output. (keyboard and file reading)
MySql的DDL和DML和DQL的基本语法
After grouping, return to the last record group in each group_ Use of concat
2022-07-22 mysql/stonedb并行hashJoin内存占用分析
Nodejs enables multi process and inter process communication
MySql的DDL和DML和DQL的基本语法
Don't compare with anyone, just be yourself
metaRTC5.0实现君正的纯C的webrtc版IPC
渗透学习-SQL注入篇-靶场篇-安全狗的安装与绕过实验(后续还会更新)