This is the 26th day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021.”


Recently, I want to review C language, so I will update an article about C language in nuggets every day! Freshmen who are just learning C, and those who want to review C /C++, don’t miss it! Solid foundation, slow down is fast!


Debugging is really important!! It’s so important!! It’s really important!!

Everyone, and beginners must practice more!! How to debug

The importance of debugging (from Baidu)

Debugging is a programmer’s most basic skill, even more important than learning a language. A programmer who can’t debug means he can speak a language but can’t write any good software!



Common mistakes

Compilation error – syntax error


Link error

1. The function is undefined

2. Wrong symbol name (undefined identifier)


Compile, link, run


9. Common code tricks

1.Assert using Assert -> Prevent null pointer references to header files#include<assert.h>
    
2.Try to useconstEmbellishment - for strings that do not need to be changedconstmodified3.Develop a good coding style4.Add the necessary comments5.Avoid coding pitfallsCopy the code

10. The difference between NULL and NULL

When reading documents:NULL: Null pointer null-\0

null - \0
Copy the code

15. On function returns

//err

int* test(a)
{
    int a = 10;
    return &a;
}
int main(a)
{
    int *ret = test();
    *ret = 0;
    return 0;
}
Copy the code

Cause: A is a local variable, opened in the stack area. When the function returns, the a-space is destroyed, that is, the address of the a-space has been given back to the operating system, but the RET receives the address of the local variable, causing illegal access


That’s all for today. Thank you for seeing us! Hope to help you! You are welcome to click on this topic and subscribe! At the same time, welcome the bigwigs to criticize and correct!