C problem of language diversity

c language% -6d: 6 represents the output column width is 6 characters,
characters if the actual output is less than 6, a space is supplemented with the remaining positions,
if the actual output is greater than six characters at the actual width of the output, in front of the negative sign indicates that fill the space on the right
if there is no negative sign indicates that fill the space on the left.
Digital is just a few tables are a few spaces.
which is:

printf("%-6d",123);

The resulting output is (a decimal point represents a space):

  123...

printf("%6d",123);

The resulting output is (a decimal point represents a space):

123 ...
as printf ( "% 4d", 12 ) is __12 output format (in front of two spaces) printf ( "% 4d", 12345) directly output 12345

% 2.5f expressed in floating-point format values of the output variables, a width of 2 to 5 decimal places, the width is not enough to the actual subject
% m.nf: output accounted for m columns, where n has a decimal places, such as the numerical width m is less than fill the space left. 
% -m.nf: output accounted n columns, where n has a decimal places, such as the value m is smaller than the width of the right end of the meeting spaces.

Further description of the printf function:
If you want to output the character "%", two consecutive% should be indicated by a "format control" string, such as:
printf ( "% F %%", 1.0 /. 3);
output 0.333333 %.

#error: cast from 'int *' to 'int' loses precision #
This is because the system Linux 64-bit pointer type occupies 8 bytes, and an int 4 bytes, so there will loses precision.

可以先将int* 转成long类型,long类型可以隐式类型转换到int类型,如下:

      int func() {
          int *p;
          p = //赋值
          return (long)p;
          }

4.11 2019
static int A you can be understood as a global variable, if you are declared in the class A,
then you are no matter how many A new, then you visit Aa, share the same values.
And int a, the value of A different example where independent.


Refers to a constant pointer - the pointer to the constant, by definition, is a pointer to a constant, i.e., it does not point to a variable that points to the content can not be changed, can not modify the contents of the pointer to point to it, but not a constant pointer itself , its own value can be changed, so that a constant point to another.
It refers to a constant pointer - the pointer itself is constant. It points to the address can not be changed, but the contents of the address can be changed through a pointer. It points to the address associated with his life until the end of life. One thing to note is that while the initial value pointer constants must be defined at the time.

2. The method of using
the difference in the wording:
constant Pointer: const the prior pointer constant: const in the following.
Example of use:
(1) a constant pointer Use:
As B int, C;
int const A;
A = & B;
A = & C;
can be, except that it points to the content can not be modified. Such as:
A = 20 is; it is illegal! error!
(2) using the pointer constant
, such as a int, B;
int const * p = & a;
represents p is a constant pointer that points to a memory variable. P constants can not be reused pointer pointing to other variables, such as p = & b; Error! You can modify the value of the memory points, such as: * p = 20; when the pointer must be declared as a constant initial value as the formula.
Pointer constant can not be released, with p at NULL, i.e.,
p = NULL;
will be given at compile time
/opt/test/test.c:649: error: assignment of read- only variable `p '
there is a different remember them in the form of tips! Const keyword look, he can not be modified later, such as int * const a = & b; followed by a, a can not modify the description!
int const * a = & b; followed by a description is a non-modified!


int main (int argc, char const * argv []) in
argc records the number of user input on the command line parameters to run the program.
arg [] array pointed to at least one character pointer that arg [0]. He usually point to the file name of the executable file of the program. In some versions of the compiler also includes the path to the program file is located.
is the number of parameters argc, argv [] parameter, argv [0] is the file name, argv [1] is the first argument ...


Role of the braces is to enclose the statement as a whole, you can use it as a statement.
If the statement is executed if the loop back determination or else while for only one, the braces can be omitted .

Guess you like

Origin www.cnblogs.com/luoyuliang/p/10584952.html