A few pens, recording my C language blind spot notes, only for the previous experience, but also wrong, can communicate.
is there a difference between 1.int* a and int *a?
No matter what the difference, it is said that a is an int pointer is suggested to write an int *a; this is obvious for example the following int *a,b;a is a pointer, B is a shape, a clear but you assume to write int* a, b; An inattentive. I think B is a pointer.
The data type of the 2.C language and the Microcontroller C language Char, the former is the string type, the latter is the same as the INT 8-bit data type
3.C Language malloc application structure is stored in vivo. Release with free
4.C language function cannot return the address of a local variable
#include <stdio.h>
Char *returnstr ()
{
char *p= "Hello world!"; Agree
return p;
}
int main ()
{
Char *str;
Str=returnstr ();
printf ("%s\n", str);
return 0;
}
- #include <stdio.h>
- Char *returnstr ()
- {
- Char p[]= "Hello world!"; Error, array space is a temporary variable, in the Stack area
- return p;
- }
- int main ()
- {
- Char *str;
- Str=returnstr ();
- printf ("%s\n", str);
- return 0;
- }
5. Returns a pointer to the heap memory that is capable of
- char *getmemory3 (int num)
- {
- Char *p = (char *) malloc (sizeof (char) * num);
- return p;
- }
- void Test3 (void)
- {
- char *str = NULL;
- str = GetMemory3 (100);
- strcpy (str, "Hello");
- cout<< str << Endl;
- Free (str);
- }
#include <stdio.h>
//D is also a local variable in this function. The function runs out of its own initiative to destroy, but the space allocated by the pointer is not actively collected by itself, unless the program ape Delete.
// so this will output normally.
Char*a ()
{
Char*d ="ZET";//one form of initialization, equivalent to allocating four of space
returnD
}
//However, the second array space is maintained by the system. The function runs out of its own initiative to destroy
Char*b ()
{
Charp[Ten] = {"3G Platform"};
returnP
}
The above two columns are fully explained. In the C language. String constants. Unlike character array storage, the former is stored in a string constant area, which is a temporary memory opened up in the stack, although the value of a is specified at compile time (so the values of a cannot be changed)
//The number of arguments is the way the value is passed, changing the address of the shape, and the address of the pass is not changed .
voidCintNChar*pname)
{
Char*a[4] = {"AAA","BBB","CCC","DDD"};
PName = A[n];
}
voidMain ()
{
intn=0;
Char*pname ="DB";
printf"%s\n", a ());//Output Zet
printf"%s\n", b ());//Random Output garbled
C2, pName);
printf"%s\n", pName);//The output db, because char *pname = "db", has made the pName point to DB, but C (2,pname), and cannot change the address that the pName points to.
//The image Point says is: I have a box for you to use. You can put something in it, but you can't replace my box with another one.
// in this case, it is not possible for a function call to make pname a two-dimensional array in a function.
scanf ("%d", &n);
This example fully demonstrates that in a function, you cannot convert an address represented by an incoming pointer, such as P=A, at which point the P is the function on the stack.
No longer represents the address represented by the actual participation, and the next step is to indicate that if the function is given a value, the shape will take a memory.
And the content of the actual participation is not changed, so the pointer can only change the content of its point, change his value (address) is meaningless.
The main function is the address of the actual parameter is not changed
6. When dealing with string operations, it is best to use standard string manipulation functions, such as Strcpy,strcat. STRCMP, etc.
At the same time, the incoming pointers to these functions are initialized to a char type and cannot be unsigned char otherwise, such as the following warning pointer targets in passing argument 1 of ' strlen ' differ in Signedness
7, a level pointer is passed in the function, can change the value specified by the function. A level 2 pointer can change where the pointer is pointing.
The int data type in the 8.C language is coerced into char, preserving only the lowest 8 bits, such as int a;(unsigned char) a.
The char type (1 bytes) is assigned to the int type (2 bytes): The value is assigned to the lower 8 bits of the Int. High 8-bit complement 0
9,int in *p and Char *p. p++, it seems in memory space. The former moves 4 bytes of int type data. The latter only moves 1 bytes.
Operation of files in C language embedded development is mainly Fopen,fread,fwrite, these operations mainly for 2 binary files for data reading and writing,
FOPEN:WB just write open or create a new binary file. Just agree to write the data. RB read/write opens a binary file. Just agree to read and write data. AB means to run read and write
11. The difference between an array of strings and a normal string is that the latter allocates memory at its own initiative and adds an ASCII 0 to the end symbol . namely 0x00.
12.
the names of the arrays in the C language cannot be changed. The array name is compiled with the implicit pointer constant Const. The program does not agree with the change
The C language defines a string that can be used with pointers as well as arrays, such as:
Char *s= "Hello"; "Hello" is a string constant, which belongs to the const type. S is a pointer to a string constant that can only be read. is not agreeable to change. cannot be written as s[0]=x, but can change the value of the pointer. Make it point to a different constant. such as S = "Xeron";
(2) char s[]= "Hello";//pointer constant, the value of s itself cannot be changed. But can change what it points to, S[0]=x
The difference between the two is
(1) The former definition of the string in the program can not be changed, because it is stored in the Code section, character constant area;
(2) The latter defined string can be changed. It is stored in a data segment or stack.
String array to consider when changing the contents of strings
13.fread and fwrite open buffers, it is best to use a char type pointer as the address of the buffer
You need to specify the size of buffer at the same time, otherwise segmentation fault error will occur
14. Be good at using forced conversions of data types. This is closely related to the storage structure of the data in memory.
The 15.C language function participates in the stack order from right to left. Makes it possible to determine the number of dynamic parameters.
C Language Blind spot note 1