当前位置:网站首页>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-25 01:11:00 【InfoQ】

Preface

One 、C Language program structure
1.1 Program structure
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.1.2 Start and end
1.1.3 Function composition
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
#include <stdio.h>
void main()
{
int a,b,sum;
a=123;b=456;
sum=a+b;
printf("sum is %d\n",sum);
}
- 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 )


2.2 Case 2
#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);
}
- 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


summary

边栏推荐
- unresolved external symbol [email protected] resolvent
- Sort out some scattered knowledge points by yourself
- Custom type
- Summary of MATLAB basic grammar
- ASP rs.open SQL, Conn, what does 3, 1 stand for in 3,1?
- Uxdb resets the password without knowing the plaintext password
- Detailed explanation of the usage of vector, queue and stack
- Example analysis of enum data type in MySQL
- Interview questions
- Method properties of ASP adodb.stream object
猜你喜欢

Example analysis of recombinant monoclonal antibody prosci CD154 antibody

Fabric. JS centered element

Listing of China graphite: the market value is nearly HK $1.2 billion, achieving a zero breakthrough in the listing of Hegang private enterprises
![[25. Hash table]](/img/c4/1500d070d44d3bd84eb141ed38013d.png)
[25. Hash table]

Financial RPA robot enables enterprises to open a new era of intelligence

Tool use of rookie tutorial -- View subclass (implementation class) class diagram in idea
![[C + + primer notes] Chapter 8 IO Library](/img/84/53cca8bb00b392c74b5dfe039da711.png)
[C + + primer notes] Chapter 8 IO Library

7.24 party notice

Example analysis of enum data type in MySQL
![Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation](/img/e1/51f750d355b248ab84e10f0e134271.png)
Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation
随机推荐
Dynamic kubernetes cluster capacity expansion of airbnb
Educational codeforces round 89 (rated for Div. 2) ABC problem solution
The current situation of the industry is disappointing. After working, I returned to UC Berkeley to study for a doctoral degree
What are the functions of rank function
[C + + primer notes] Chapter 8 IO Library
How to implement a state machine?
Worthington carboxyl transfer carbonic anhydrase application and literature reference
WhatsApp web for usability testing of software testing technology
How SAP Spartacus redefines login component
WPF implements RichTextBox keyword query highlighting
Pytorch structure reparameterization repvggblock
Divide 300000 bonus! Deeperec CTR model performance optimization Tianchi challenge is coming
7.24 party notice
Which automation tools can double the operation efficiency of e-commerce?
Latex notes
Redis pipeline technology / partition
This visual is not connected to the presentationsource.
How to create an index
Related knowledge of paging
Harbor installation