Table of contents
1. What does %m.ns print string mean?
4.int (*a)(int)和int (*a[10])(int)
5.printf and big and small endian
1. What does %m.ns print string mean?
m: the width of the output string
n: Intercept n characters of the target string from the left, right-align, and add spaces
If the length of the string>n>m, the function of m will be invalid at this time, only n will work
If n>string length, automatically stop printing when \n is encountered
If %-m.ns represents left alignment
For example
m=3 indicates that the interception width is 3
n=2 Intercept 2 characters from the left
If there is no negative sign (-), the default is right alignment, and if it is not enough, the space will be automatically filled
For the printing of floating point numbers, m still has the same meaning, but n means precision
m=10 indicates that the interception width is 10, n=2 indicates that two digits are reserved after the decimal point, and the insufficient width is filled with spaces
2. const and *
look at these three p
A brief introduction to constant pointers and pointer constants
Constant pointer: The value of the space pointed to by the pointer cannot be changed, and the value of the space pointed to by the pointer cannot be modified by dereferencing the pointer, but the point of the pointer is variable
Pointer constant: the pointer is constant, the pointing cannot be changed, but the content of the space pointed to can be changed, and the value of the space pointed to can be changed by dereferencing the pointer
This is too obscure. Simply put, the position of const and * determines who cannot be changed (whoever is modified by const has constancy)
const int * a: const is before *, indicating that the content after dereferencing is modified by const, which cannot be changed, and has constant attributes
That is, the value pointed to by the int* pointer cannot be changed—constant pointer
int const * a: const is still before *, same as above
int * const a: Now a is modified by const, the type of a is int*, and the pointer is modified—the pointer is constant, and the pointer cannot be changed, but the content of the pointed space can be changed
3. Operator precedence
You can look up the table yourself, but there are some very common ones:
Parentheses have the highest priority
[ ] > * > +
Also, the precedence of these operators is lower than +-*/
4.int (*a)(int)和int (*a[10])(int)
The first * combined with a is a pointer, and the pointer points to int (int), that is, there is an integer parameter int, and the return value is int
The second [ ] has a higher priority than *, so a[10] represents an array, and the array type is int (*)(int)
This * refers to the pointer, the pointer points to int (int), that is, it points to the function, the return value of the function is int, and there is an integer parameter that is int
5.printf and big and small endian
Review endian machines
Little endian: store low addresses in low bits
Big endian: store high addresses in low bits
Take a look, the title says this is a little endian machine
if big endian
Now we call the printf function
Create a function stack frame (the stack grows from high address to low address)
The variables of printf are read from right to left, that is, read c first
And the stack is first in last out
So first read at the low address of the stack, print %d, and read 4 bytes at a time from the low address (top of the stack)
So the final result is 1 0 2
6. Two-dimensional array
The initialization of each row of a two-dimensional array must be continuous, that is, it cannot be initialized with {0,,2}
Initialization cannot omit the number of columns
And when calculating the two-dimensional array **a[3][4], first specify that the two-dimensional array has three rows and four columns, and the array stores pointers (4 bytes under 32 bits)
So the occupied space is 3*4*4=48 bytes