当前位置:网站首页>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:04:00 【Hua Weiyun】
Pay attention to ah zap !
Preface :
*️ Author's brief introduction : A bowl of soybean paste *️ What brings happiness to everyone is aja me !
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 | |
@TOC
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. ! friends !

边栏推荐
- 7.20 - daily question - 408
- Pytorch structure reparameterization repvggblock
- Uxdb resets the password without knowing the plaintext password
- Windows security hardening -- close unnecessary ports
- What are the functions of rank function
- Where is the most formal account opening for futures trading? Capital security?
- The number of palindromes in question 9 of C language deduction. Two pointer array traversal method
- Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation
- Tiktok iqiyi announced cooperation, long and short video handshake and reconciliation?
- C language force buckle the flipped number of question 7. Violence Act
猜你喜欢

7.14 - daily question - 408

What is iftmcs indicating contract status message?

Invitation letter | "people, finance, tax" digital empowerment, vigorously promote retail enterprises to achieve "doubling" of economies of scale

Heavy forecast! Analysys, together with Microsoft and the Central University of Finance and economics, talks about the digital economy

Specificity and five applications of Worthington alcohol dehydrogenase

Introduction to thread pool

MySQL Basics (concepts, common instructions)

Example analysis of recombinant monoclonal antibody prosci CD154 antibody

Pytorch structure reparameterization repvggblock

BGP机房和BGP
随机推荐
7.19 - daily question - 408
如何创建索引
C language force buckle the flipped number of question 7. Violence Act
asp rs.open sql,conn,3,1中3,1代表什么?
第四章 驱动子系统开发
Current events on July 20
7.14 - daily question - 408
Game partner topic: the cooperation between breederdao and monkeyleague kicked off
The leftmost prefix principle of MySQL
Password input box and coupon and custom soft keyboard
"Usaco2006nov" corn fields solution
How to better use the touchpad of notebook
Specificity and five applications of Worthington alcohol dehydrogenase
Wireshark introduction and packet capturing principle and process
[performance optimization] MySQL common slow query analysis tools
Pursue and kill "wallet Assassin" all over the network
Screenshot of Baidu map
Advanced multithreading (Part 2)
How to use measurement data to drive the improvement of code review
[C + + primer notes] Chapter 6 functions
