当前位置:网站首页>1、 C language program structure, compilation and operation, data type related
1、 C language program structure, compilation and operation, data type related
2022-07-26 17:53:00 【Rock magnon】
List of articles
1、C Language program structure
- Preprocessing instruction : Tell the calculator before the official compilation , To include the corresponding header file
- The main function :int main() Where the program starts
- Return value :return 0; At the end of the program , The result returned , The same type as the main function
// 1. Preprocessing instruction , Tell the calculator before the official compilation , To include the corresponding header file
#include<stdio.h>
// 2. Where the program starts
int main(){
printf("hello world!\n");
return 0;// After the function terminates , return 0
}
2、 Compiling and running process
- compile :
- Format :gcc Source file .c -o Object file's .out
- Be careful : Multiple files can be compiled at the same time
gcc test1.c test2.c -o main.out - Specify the location where the target file is generated
gcc test1.c -o Target file /main.out - -o The two documents before and after are interchangeable , The effect is the same
gcc -o main.out test1.c - Be careful : stay Windows in , The suffix of the target file is .exe
- perform :
- command :
./main.out
- command :
3、 Data type related
1. View data store size
- Code implementation :
#include<stdio.h> int main(){ printf(" Storage size :%ld byte \n",sizeof(double)); return 0; } - Running results :
Storage size :8 byte
2.float.h Related macro definitions
- stay float.h Header file , Defines related macros
- Code implementation :
#include<stdio.h> #include<float.h> int main(){ printf("float Store the maximum number of bytes :%lu\n",sizeof(float)); printf("float minimum value :%E\n",FLT_MIN); printf("float Maximum :%E\n",FLT_MAX); printf(" double-precision value :%d\n",FLT_DIG); return 0; } - Running results :
float Store the maximum number of bytes :4 float minimum value :1.175494E-38 float Maximum :3.402823E+38 double-precision value :6
3. Data type conversion
3.1 Automatic conversion
- Assign floating point numbers to integers , The decimal value will be automatically removed
- Integer assigned to floating point number , The value remains the same , But it will be stored in floating-point variables
3.2 Coercive transformation
- Format :( Type specifier )( expression )
- Code implementation :
#include<stdio.h> int main(){ float f,x = 2.3, y = 4.3; int i = 4,a,b; a = x + y;// The decimal part will be removed b = (int)(x + y); f = 10/i;// Divide two shapes , The result is still plastic , The result is 2, then 2 Stored in floating point type printf("a=%d,b=%d,f=%f",a,b,f); return 0; } - Running results :
a=6,b=6,f=2.000000
边栏推荐
- [training Day2] torchbearer
- #夏日挑战赛# OpenHarmony基于JS实现的贪吃蛇
- Spark data format unsafe row
- Cross Site Request Forgery (CSRF)
- Comparison between agile development and Devops
- On the growth of data technicians
- 【集训Day2】cinema ticket
- Common super easy to use regular expressions!
- We were tossed all night by a Kong performance bug
- Performance tuning bugs emerge in endlessly? These three documents can easily handle JVM tuning
猜你喜欢

Gan (generative adversarial network, GaN) generative countermeasure network
![[cloud native] IVX low code development was introduced into Tencent map and previewed online](/img/f1/40ca06bf65fbc0097f5b61ec7d2509.png)
[cloud native] IVX low code development was introduced into Tencent map and previewed online

Come on developer! Not only for the 200000 bonus, try the best "building blocks" for a brainstorming!

硬件开发与市场产业

JS 闭包 模拟私有变量 面试题 立即执行函数IIFE

Week 16 OJ practice 1 calculates the day of the year

#夏日挑战赛# OpenHarmony基于JS实现的贪吃蛇

kudu设计-tablet

JS function scope variables declare that the variables that promote the scope chain without VaR are global variables

Pay attention to the traffic safety warning of tourism passenger transport issued by the Ministry of public security
随机推荐
AI zhetianchuan ml unsupervised learning
AI zhetianchuan ml integrated learning
Sequential storage structure of linear table -- sequential table
Spark data format unsafe row
Overview of the agenda of the keynote speech of apachecon Asia, an international celebrity vs a local open source star
股票公司开户万一免五这是真的安全靠谱的吗
Heavy! The 2022 China open source development blue book was officially released
leetcode:1206. 设计跳表【跳表板子】
2.1.2 同步始终失败
Interview with celebrities | open source is a double-edged sword for security -- Wei Jianfan, author of the Chinese translation of cathedral and market
Sign up now | oar hacker marathon phase III midsummer debut, waiting for you to challenge
6-19漏洞利用-nsf获取目标密码文件
PIP installation module, error
Zhaoqi science and technology innovation overseas high-level talent introduction platform, entrepreneurship event Roadshow
Performance tuning bugs emerge in endlessly? These three documents can easily handle JVM tuning
Cross Site Request Forgery (CSRF)
二层管理型交换机如何设置IP
[300 opencv routines] 240. Shi Tomas corner detection in opencv
图的遍历的定义以及深度优先搜索和广度优先搜索(一)
如何组装一个注册中心?