当前位置:网站首页>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 .
边栏推荐
- 【方向盘】IDEA的代码审查能力,来保证代码质量
- Input some data and find the maximum output. (keyboard and file reading)
- 你不可能让每个人都满意!
- 先爱自己,再爱别人。
- 17. 什么情况用ArrayList or LinkedList呢?
- You can't satisfy everyone!
- 变量和数据类型(04)完结
- 8. Use the quadratic geometry technology to draw a small column on the screen.
- [USB voltmeter and ammeter] Based on stm32f103c8t6 for Arduino
- STM32H750VBT6驱动程控增益放大模块PGA113——基于CubeMX的Hal库
猜你喜欢

Tensorflow Einstein function

C language to achieve three chess? Gobang? No, it's n-chess

UE4/5 无法打开文件“xxx.generated.h”(Cannot open file xxx.generated.h)的解决方法总结

第二部分—C语言提高篇_4. 二级指针

tensorflow scatter_nd函数

聚合型新生态模式-分享购,会员及奖励制度
![[USB voltmeter and ammeter] Based on stm32f103c8t6 for Arduino](/img/5f/40e4e144a628ef1aa38ab536b40366.png)
[USB voltmeter and ammeter] Based on stm32f103c8t6 for Arduino

10分钟就能写出来的——25~30K的国外企业招聘面试考题,这不是轻轻松松吗~

C语言中extern,static, register,volatile 关键字的作用;保姆级教学!

One book a day: machine learning and practice -- the road to the kaggle competition from scratch
随机推荐
Vs debugging
反射
第二部分—C语言提高篇_1. C语言概述
第二部分—C语言提高篇_3. 指针强化
项目问题积累
STM32基于hal库的adc以DMA的多通道采样以及所遇问题解决
tensorflow boolean_mask函数
树莓派换源
SparkSQL核心使用,220724,
Sealos packages and deploys kubesphere container platform
Input the names of 10 people and output them in descending order
Libevent and multithreading
Penetration learning - SQL injection - shooting range - installation and bypass experiment of safety dog (it will be updated later)
使用root用户为创建新用户并设置密码
GE口:SGMII模式和serdes模式
C language to achieve three chess? Gobang? No, it's n-chess
Introduction to pyqt5 - student management system
一日一书:机器学习及实践——从零开始通往kaggle竞赛之路
Do you really know the judgement sentence?
(笔记整理未完成)【图论:求单源最短路径】