Summary of C/C++ Language Fragmentary Knowledge Points (1)
In the past three years of university study, I have encountered a lot of knowledge and problems scattered, but some will be forgotten after a long time. In order to overcome this problem, I thought that I could use a blog to keep records, which is convenient for vagueness. When I go back and learn again.
First, look at the code:
# include <stdio.h>
int main(void){
char side_a[] = "Side A";
char dont[] = {
'w','o','w','!'};
char side_b[] = "Side B";
puts(dont);
return 0;
}
Would you be a little surprised at the results of the operation, don’t you think that the output of the puts function should not be the "wow!" string in dont? Why is there still Side A, and why can’t it be Side B behind?
Don't worry, the blogger will answer for you.
Knowledge point 1: puts() function analysis:
I believe that the pretty girls who passed by this blog post at this moment must already be familiar with the correct use of the puts() function. If you don’t understand it, it’s okay. The blogger is very careful and has attached a learning link.
1. puts() function Baidu Encyclopedia
2. C language puts() function usage details
Let's return to the topic, yes, the most important point of the puts() function is that the puts function will not end until it encounters the terminator "\0", otherwise, the computer will look down in the memory until it encounters an empty space. The character ends, so if there is no end sign, the puts function may output garbled characters.
Knowledge point 2: The storage area of each variable of C/C++ is different.
The storage area of each variable in the C/C++ program in the memory:
1. Memory stack area: store local variable names
2. Memory heap area: store new or malloc objects;
3. Constant area: store the value of local variables or global variables;
4. Static area: store global variables or static Variable;
5. Code area: binary code.