当前位置:网站首页>Embedded engineers should make good use of the three elements of C language
Embedded engineers should make good use of the three elements of C language
2022-07-21 13:48:00 【an520_】
As an embedded Engineer , How to write efficiently 、 Clear thinking C What about language programs ?
Use C Language thinking mode to construct the framework of the program
Have a good C Fundamentals of language algorithms , In order to realize the logical framework of the program
Flexible use of C Pointer operation of language
Although it seems that the above statement is very abstract , It feels like falling into the fog , In fact, it is to use C There is a problem with language 、 The process of analyzing and solving problems .
Embedded engineers are writing C When it comes to language programs , We should build the program architecture for the problems encountered .
For example, we have to deal with “ Monkey chooses King ” The classic question of : A group of monkeys , Form a circle hand in hand , Start with any monkey 1 Start counting , When you encounter a number to exclude ( Preset ) When the monkey exits the circle , Start with the next monkey and continue from 1 Number off , So again and again , Finally, the remaining monkeys are the king of monkeys .
use C The thinking mode of language is used to construct the program framework
The program is divided into three parts :
a、 Data acquisition , In order to run the program , The above question is to get the total number of monkeys , Start with the monkey and eliminate the number ;
b、 Data operation , You need to eliminate the corresponding data from a pile of data , Pay attention to the correctness of logic ;
c、 Increases the speed of the program , Use fewer loops and more pointers .
use C Language for logical implementation
a、 Data acquisition , adopt printf and scanf Get the parameters .
At the same time, pay attention to the handling of exceptions , Like the two above if A statement is the judgment of an exception , Each exception corresponds to a different return value , This facilitates the debugging of the program process and the legitimacy of the data .
b、 /* Define the node type of the linked list */
Build a circular linked list for “ monkey ” Circle construction .
After this step ,head and p(present) Has become a “ Monkey ring ” The linked list of . In the process of building the linked list, we need to pay attention to the following points : Memory development , At this time, the principle of how much to use and how much to open up .
If you open up too much at once , Can cause memory leaks , however , This small program will not encounter this problem . The second is to be familiar with the construction method of circular linked list : The tail of the list points to the head of the list . At this time, if you want to, you will also think of the situation of two-way linked list .
c、 /* Find No k Nodes */
Find where to start counting . here ,p Point to the beginning “ monkey ”. Because the linked list method is used , This process only needs to focus on p Pointer next Just point .
a、 Save the initial “ monkey ” Circle parameter .
Why keep this ? First, control the number of monkeys , So keep all the numbers . Next use q(qurry) To keep the linked list in front of the monkey , And connect the linked list after removing monkeys . such , Completed the element deletion of the circular linked list .
b、 Monkeys count .
Monkey counting is the key to the whole program , The following tasks need to be completed :a、 Find the beginning “ monkey ” Count ;b、 Delete the “ monkey ”;c、 Connect the head and tail of the deleted circular linked list .
Through the above data operation , You can delete the corresponding linked list elements , This may be C The charm of language programs .
Use C The pointer to language
For example, the definition of the linked list pointer of this program ,p,s,q.
We know , Pointer operation can not only reduce the memory required for data operation , It can also improve the running speed of the program .
The advantages of pointers , Perhaps it is not obvious in this procedure , In the case of a large amount of data and sensitive to the requirements of operation speed, it will be obvious , such as Linux The kernel , There will be a good embodiment .
All in all , For embedded engineers , Not only can we design good hardware circuits , If we can write good software programs, our life will be better .
【 Learning exchange group :607439754】
【 Share some learning materials below , You can see what you are interested in 】:
Internet of things embedded engineer network foundation
Embedded development - Interprocess communication details
Necessary for embedded engineers Web knowledge
Application of data structure in embedded .
Embedded application lightweight database .
Embedded operating system uC/OS
【 Share some online disk information packages below , If you need it, you can collect it yourself 】:
边栏推荐
- 为啥有些经理,总是强行刷存在感?(你遇到过吗?)
- 活动报名|揭露 Apache Doris 数据湖分析技术内幕?稀土开发者大会免费报名中!
- How do PR video editors choose notebooks? ASUS lingyao pro16 2022 brings you to play with content creation
- 5款经典代码阅读器的使用方案对比
- 详细设计说明书的内容要求
- 【WebFace260M】《WebFace260M:A Benchmark Unveiling the Power of Million-Scale Deep Face Recognition》
- [speech recognition] hidden Markov model HMM
- What are the main aspects of troubleshooting when DTS write module delays writing to the target database?
- 服饰行业如何将实体经济做得有智慧?
- How to use DTS data subscription to obtain incremental data of DTS cache module?
猜你喜欢
认识和使用日志工具Loki
Redis(12)----Redis服务器
All countries know the highest salary level of programmers, and the bottom is unexpected
5款经典代码阅读器的使用方案对比
【WMCA】《Biometric Face Presentation Attack Detection with Multi-Channel Convolutional Neural Network》
【MLFP】《Face Presentation Attack with Latex Masks in Multispectral Videos》
Openbmb x Tsinghua NLP: the 20 hour large model open class will take you from introduction to mastery
Daily question brushing record (29)
7.6 balanced binary tree (AVL tree)
Know and use log tool Loki
随机推荐
TP5 控制器中foreach循环语句
Dart:补充
MySQL---three 多表查询与事务的操作
渗透测试-命令执行注入
Unity API details - GameObject class
直播app系统源码,给视频背景添加上水印
视频融合云平台EasyCVR重启服务器后,级联离线如何解决?
设置Shell脚本开机自启
【软件测试】测试中的风险有哪些?
反转字符串——中间递归
crobtab不执行定时任务的原因及解决办法
云计算与数字化转型的关系,终于有人讲明白了
科学计算工具包SciPy傅里叶变换
出现DTS 写入模块写入目标数据库延迟,主要排查哪几个方面?
7.7 B tree and b+ tree
Laravel used with JWT
服饰行业如何将实体经济做得有智慧?
如何搭建一个知识库网页?
狂神redis笔记04
一张光盘和一张软盘