当前位置:网站首页>Take C language from 0 to 1 - program structure and use examples
Take C language from 0 to 1 - program structure and use examples
2022-07-22 01:02:00 【A bowl of soybean paste】
Pay attention to ah zap !
Preface :
*️ Author's brief introduction : A bowl of soybean paste *️ What brings happiness to everyone is aja me !
CSDN Diligent writing model !、 Shanglan village programming expert !
motto : Success is not only in the future , It's from the moment you decide to do it , It's accumulated over time .
🧙 Due to the limited knowledge reserve , If there is a problem in the article , Please correct !thanks!
If you like aja's article, you can give it to Sanlian Or often come to see a sauce lying 🥺
Series index :
Series name | link |
---|---|
from 0 To 1 Take down C Language — The introduction | The introduction |
from 0 To 1 Take down C Language — Program structure and use examples | |
List of articles
Preface
Bo master slave 0 To begin C The analysis of language , Guide readers vividly c Language learning , Don't copy mechanically !🧙*️🧙*️🧙
Everyone is happy to study together C!
One 、C Language program structure
1.1 Program structure
1. Any programming language has its own grammatical rules and prescribed expressions .
2. Computer programs can only be written in strict accordance with the grammar and expression specified by the computer language , In order to ensure that the written program can be correctly executed in the computer , It is also easy to understand and read .
The programs are all from main The function starts executing , Any program main Functions are indispensable , It is the entrance to the execution of our program
1.1.1 Basic constituent unit
1.C Language programs must have and can only have one main) function ( Also called principal function )
2. A complete C Language program , Is written by a main() Function and several other functions , Or just one main) Function constitution .
1.1.2 Start and end
One C Language program , Always from main() The function starts executing , Regardless of its position in the program . When the main function is completed , That is, the program is completed . Habitually , Main function main( Put it first .
1.1.3 Function composition
Any function is composed of function description and function body ( Include main function )
Its general structure is as follows :
Function type function name ( Function parameter table ) → Function header
{
Data description section ; → The body of the function
Algorithm description ; → The body of the function
}
among : Data description . Used to define the variables used in this function ; The executable part , Complete specific functions , Consists of several statements .
1.2 Program writing format
- C Language statements must be semicolon “ ;” end .
- The writing format of the program line is free , It is allowed to write several statements in one line , It is also allowed to write a statement on several lines .
- “ Compact alignment , Automatic indentation ”
- Use the annotation function properly .C The annotation format of the language is :/*…*l
- The position of the note , It can occupy a single line , It can also follow the statement .
- Chinese characters are allowed in comments . Under non Chinese operating system , What I saw was a mess ,, But it does not affect the operation of the program .
Two 、 case analysis
2.1 Case a
Code block :
#include <stdio.h>
void main()
{
int a,b,sum;
a=123;b=456;
sum=a+b;
printf("sum is %d\n",sum);
}
analysis :
- First, add the compilation preprocessing command #include <stdio.h>( Add this file to the current program )
- Then write the main function
- The first line of the main function defines integer variables a,b,sum
- The second line of the main function is the setting a and b Value , That is the assignment
- The third line of the main function is to make sum=a+b
- The fourth line of the main function is the output character :sum is xx(xx yes sum Value )(%d Set integer output )
On board test :
stay devc Enter the above example :
The result is zero :
2.2 Case 2
Code block :
#include <stdio.h>
void main()
{
int a,b,sum;
a=10;
b=24;
sum=add(a,b);
printf("sum= %d\n",sum);
}
int add(int x,int y)
{
int z;
z=x+y;
return(z);
}
analysis :
- First add stdio Function header file
- Then enter main Function
- to a,b,sum The definition of (int: integer )
- And then assign it to a and b
- Then perform the sub function operation ( Here we use the call of sub functions )
- Print sum Value
- The main function ends and enters the sub function definition
- add The function is used to input two values x and y Add and output
- Then the main function calls add The result of the function is to a and b Add the value to sum
On board test :
stay devc Enter the above example :
The result is zero :
summary
This article is the second chapter , Mainly to let everyone know C Language related programming rules . This chapter requires careful study !
I think the most important thing to learn a programming language is to practice and think , We need to think more in daily life , Only by practicing more can we reach a certain height !
come on. ! Ape friends !
边栏推荐
- Draw the corresponding rectangular box on the picture according to the returned picture and coordinates
- Structured design SD
- Hcip day 2 operation 7.17
- Batch transfer (copy) files of the same type in the folder (win10)
- Process knowledge generalization
- HCIA NAT experiment report 7.14
- Automatic reference counting and circular reference
- [ar foundation] ar foundation foundation foundation
- C#/VB.NET 添加多行文本水印到Word文档
- [AR Foundation] 开发应用的基础框架流程
猜你喜欢
OpenShift Security (17) - 将 OpenShift Compliance Operator 的合规扫描集成到 RHACS
Centos安装Redis
Solve the problem that pictures inserted into word documents become unclear
hcip第八天
Attack and Defense Technology Part I - know the enemy (attack means)
OpenShift 4 - 配置OpenShift集群日志环境
Interviewer: are you sure redis is a single threaded process?
How bad can a programmer be?
Viewing the mid stage value of cloud native technology from the popularity of prefabricated buildings (II)
Sword finger offer_ Knowledge transfer ability
随机推荐
[hcip continuous update] DHCP security threat
攻防技术第二篇之-知己(防御手段)
Attack and Defense Technology Part I - know the enemy (attack means)
Attack and Defense Technology Part II - bosom friend (defense means)
[ar foundation] basic framework process of application development
[ar foundation] ar foundation foundation foundation
HCIP 第二天作业 7.17
丽华快餐订餐小程序
Based on tensorflow2.0+ use Bert to obtain Chinese word and sentence vectors and conduct similarity analysis
Record a vulnerability mining record of website penetration
the volume for a file has been externally altered so that the opened file is no longer valid
Script loads data into JSON file
Centos安装Redis
Successfully install pyinstaller (solve the problem of PIP install pyinstaller installation failure)
通过例子学C标准库<ctype.h>
[AR Foundation] 开发应用的基础框架流程
dom——防抖与节流
scrapy 直接输出json文件
Sword finger offer_ Knowledge transfer ability
OpenShift 4 - 配置OpenShift集群日志环境