当前位置:网站首页>How can I take a shortcut to learn C language in college
How can I take a shortcut to learn C language in college
2022-07-06 09:43:00 【Dafang teacher embedded】
university C How can we take a shortcut in learning language
Learning methods
C Language is the foundation of computer architecture , Many newcomers will C Language as an introductory language for learning computers . As a newcomer , I'm sure I'll feel confused , It's a mess , Then we need proper guidance . Learning a language , Different people have different ways , However, we can use other people's good learning methods for reference .
(1) Reading a book
Reading is learning the basics , The first step in learning a language is to learn basic grammar , Only by learning the basic knowledge can we have further development . Besides reading some books , You can also watch some introductory videos , After all, it's easier for others to explain and demonstrate . Later, I will also recommend some good learning books and videos , For your reference .
(2) Knock on the code
Want to learn a computer language well , Just reading books and learning knowledge is not enough . While learning the knowledge points, you must type the code yourself to practice . When you start learning to type code, you can use some lightweight compilers , such as Dev C++, After being proficient, you can use Visual Studio These larger compilers . Feel that after mastering the basic knowledge , You can start touching algorithms and data structures , Then you can brush questions to improve your level .
(3) Practice project
After learning the basic knowledge, our goal is to practice , So we can start practicing some projects . For example, write a small notepad 、 Little games 、 Calculator and other classic small projects . In the face of those black frames, you will feel very boring , When you make a small work , You'll have a great sense of accomplishment , This will also greatly enhance your interest in learning .
Learning route
To learn a language, first understand the development history of the language , In the early C The language function is actually relatively simple , As applications and scenarios change ,C The functions of language are constantly upgrading and changing , And more and more powerful . Formal learning C It is also necessary to understand the composition and working principle of the computer system before using the language , In addition, it also includes the storage mode of data inside the computer , And the conversion between hexadecimals .
Another very important point is the compilation environment and compiler learning , At the beginning of learning, you can choose some simple and easy-to-use compilers , With further study, it is also important to choose a compiler that keeps pace with the times . After learning these contents , We can start learning C Basic knowledge of language .C Language programming is inseparable from data , Almost all programs involve data , It contains integers 、 floating-point 、 Strings and so on . and C There are two forms of representing data in language : Constants and variables . Constants can be used to represent the value of data , Variables can not only be used to represent the value of data , It can also be used to store data . Variables are used to store data , Operators are used to process data . Using operators to connect variables and constants conforms to C Expressions of linguistic grammar rules are called expressions .
After learning this , Start touching structured programming statements .C There are three basic control structures of language , Sequence control 、 Cycle control 、 Selection control . Programs are always designed to solve a practical problem , Problems often involve many aspects , Different situations need to be handled differently , So these structured program statements can be said to be everywhere in practical applications , It is particularly important to master structured programming statements correctly .
If you define some variables with basic data types , Then these variables will occupy their own memory units in memory , The restrictive relationship between variables cannot be reflected , Can't show the correlation between these variables , So we call these variables “ Discrete variables ”; But if we need to operate 100 One or more numbers , Definition 100 One variable seems unrealistic , At this time, we introduce the array . An array is an ordered collection of data items of the same type , We can 100 A variable to be defined is stored in the array .
Learning pointer is learning C The most important part of language , Whether we can correctly understand and use pointers is to master C A sign of language , I don't understand C The pointer of language doesn't know what is C Language . So is the pointer C The hardest part of language , In addition to correctly understanding the basic concepts , You have to program more , More computer typing code , Just do it , It's not difficult to master the pointer .
The previous descriptions are all simple data types , You can only define some simple data information . For complex data, information cannot be defined by a single data learned above , You have to use C The complex data types provided in the language . Complex data types are C Language provides another data type different from simple data types , It greatly enriches C The ability of language to process data and information .
C Language foundation
The first part is C Language foundation , Including preprocessing instructions 、 function 、 Variables and statements . Even the simplest C Language program , These basic concepts will also be used . With a classic c Language program , Introduce c The basic structure of language 、 Format , Make us to c There is a preliminary understanding of language .
#include // The header file , yes C A file unique to the language system
int main() // The main function
{
printf(“Hello World!”); // Main function body
return 0; // Return value
}
One C Language programs have only one main function , When the program is executed, start from the main function , End in the main function ; Function consists of function description and function body ; The function description section contains a description of the function name , Function type , Definition and description of function parameters, etc ; The function body contains variable descriptions and execution statements .
2 Select structure and cycle structure
C There are three major structures in language , They are sequence structure 、 Select structure and cycle structure .
C Language order structure is to let the program execute each item in order from beginning to end C The language code , Do not repeat any code , And don't skip any code .
C Language choice structure is also called branch structure , It's about letting the program “ Round the corner ”, Selective execution code ; let me put it another way , You can skip useless code , Only execute useful code .
C The language loop structure is to make the program “ Kill a rifle ”, Repeatedly execute the same piece of code . The sequential structure is well understood , There is no need to elaborate , A brief overview of selection statements and loop statements .
There are two selection statements ,if Statement and switch sentence .
if( expression )
{
sentence 1;
}
else
{
sentence 2;
}
switch( expression )
{
case Constant 1: sentence 1; break;
case Constant 2: sentence 2; break;
case Constant 3: sentence 3; break;
default: sentence n+1;break;//( here break not essential )
}
There are three kinds of circular statements ,for Loop statement ,while Loop statement ,do……while Loop statement .
//for sentence
for( sentence 1; Conditional expression ; sentence 2)
{
The loop body
}
//while sentence
while( Conditional expression )
{
The loop body
}
// When the loop condition expression is true ( That is, the given conditions hold ), The loop body statement is executed .
//do…while sentence
do{
sentence
}while( Conditional expression )
// Cyclic conditions and while The cyclic condition is consistent .
3 Array
An array is a collection of columns of data of the same type , These data are stored next to each other in memory , There is no gap between each other .C The language array belongs to the construction data type . An array can be decomposed into multiple array elements , These array elements can be basic data types or construction types . So it's different according to the type of array elements , Array can be divided into numerical array 、 A character array 、 Pointer array 、 Structure array and other categories . Arrays are divided into one-dimensional arrays and two-dimensional arrays , When each element in an array has only one subscript , Call such an array a one-dimensional array , A one-dimensional array is essentially a linear set of data of the same type . In essence, a two-dimensional array is an array that takes an array as an array element , namely “ Array of arrays ”.
// One dimensional array definition format :
type name[size];
// for example :
int mark[5];
// Initialization of one dimensional array
//(1) For all elements of the array
int a[4]={0,1,2,3};
//(2) Assign values to some elements
int a[4]={2,3};
//(3)int a[]={1,2,3} Equivalent to int a[3]={1,2,3};
// Two dimensional array definition format :
// Type identifier array name [ Line constant expression ] [ Column constant expression ];
// for example :
int a[3][4],b[3][5];
// Initialization of 2D array
int a[][4]={ {1,2,3,4},{5,6,7,8},{9,10,11,12}};
int a[][4]={1,2,3,4,5,6,7,8,9,10,11,12};
int a[][4]={ {1},{0,3},{8}};
4 function
Every C Every program has at least one function , The main function main(), If the task of the program is relatively simple , All the code is written in main() Function , however , In actual development , The task of the program is often complex , If all the code is written in main() Function ,main() Functions will be very large and complex , Structural chaos . We can divide the code into different user-defined functions according to the logic of the program and the division of tasks ,main() Functions are more concerned with business logic and processing flow , When specific tasks need to be performed , Just call other custom functions . The essence of introducing function is to decompose a complex task into subtasks , Each subtask is a smaller functional module , Through the implementation of these small functional modules to achieve complex problems , Thus, the more complex problems become simple .
/* Type identifier function name ( Data type parameters [ Data type parameters ......])
{
Description statement part ;
Executable statement part ;
}*/
// for example :
int max(int a,int b)
{
int m;
m=(a>b?a:b)
}
main()
{
int x,y,k;
scanf("%d%d",&x,&y);
k=max(x,y);
printf("%d",k);
}
5 The pointer
If you don't learn the pointer, you don't learn C Language ! Pointer is C The essence of language , It's also C The difficulty of language , Crack C Language pointer , Will let you C The language level has improved by leaps and bounds . The so-called pointer , That's the address of the memory ; The so-called pointer variable , That is, the variable that holds the memory address . however , People often don't distinguish between the two concepts , But confused together , If necessary , We should also pay attention to distinguish . We need to focus on pointer and address 、 Pointers and function parameters 、 Pointers and arrays 、 Pointer array, pointer to pointer and pointer to function, etc .
6 Structure
C A language struct is essentially a custom data type , It's just that this data type is more complex , By int、char、float And so on . You can think of a structure as an aggregation type . The structure part focuses on learning, including the definition method of structure 、 Reference method of structure 、 Array of structs 、 Concept and application of structure pointer 、 Structures and functions .
In actual development , We can put a set of different types of 、 But the variables used to describe the same thing are put into the structure . for example , Students in school have names 、 Age 、 height 、 Performance and other attributes , After learning the structure , We don't need to define more variables , Just put them all in the structure .
struct Student{ // Declared structure
char name[20]; // full name
int num; // Student number
float score; // achievement
};
struct Student stu1; // Define structure variables
Learning video
Now the Internet is so developed , Online learning resources are also very rich . You can find your own learning videos on the Internet .C The explanation of basic theoretical knowledge of language is perfect ; Step by step , From easy to difficult , Learning is easy ; Language organization is rigorous , Funny , It's easy to accept , Let you have the motivation to learn all the time .
边栏推荐
- Meituan Er Mian: why does redis have sentinels?
- May brush question 27 - figure
- Leetcode:608 tree node
- 发生OOM了,你知道是什么原因吗,又该怎么解决呢?
- Global and Chinese market of airport kiosks 2022-2028: Research Report on technology, participants, trends, market size and share
- Workflow - activiti7 environment setup
- 51单片机进修的一些感悟
- [deep learning] semantic segmentation: paper reading: (2021-12) mask2former
- Lua script of redis
- 单片机如何从上电复位执行到main函数?
猜你喜欢
What you have to know about network IO model
Redis分布式锁实现Redisson 15问
Redis core configuration
Mapreduce实例(七):单表join
Summary of May training - from a Guang
嵌入式开发中的防御性C语言编程
MapReduce instance (VI): inverted index
Servlet learning diary 8 - servlet life cycle and thread safety
leetcode-14. Longest common prefix JS longitudinal scanning method
MapReduce instance (IX): reduce end join
随机推荐
Global and Chinese market of cup masks 2022-2028: Research Report on technology, participants, trends, market size and share
五月集训总结——来自阿光
Global and Chinese market of capacitive displacement sensors 2022-2028: Research Report on technology, participants, trends, market size and share
【深度學習】語義分割-源代碼匯總
Redis' performance indicators and monitoring methods
听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
为什么大学单片机课上51+汇编,为什么不直接来STM32
Leetcode:608 树节点
Keep these four requirements in mind when learning single chip microcomputer with zero foundation and avoid detours
June brush question 02 - string
Solve the problem of too many small files
硬件工程师的真实前途我说出来可能你们不信
Mapreduce实例(五):二次排序
嵌入式中的合作开发--函数指针
IDS cache preheating, avalanche, penetration
Libuv thread
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
MapReduce instance (V): secondary sorting
33岁可以学PLC吗
[Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology