C traps and defects study (Chapter 3)

1. char a [10] = {}; * (a + i) given a [i] like the.

    Since a + i and i + a meaning of the same, so a [i] and i [a] have the same meaning.

int main()
{
char data[3] = {1,4,8};

printf("%d  %d\n",2[data],data[2]);

return 0;

} // output: 88 

2. int * ap; ap is a pointer pointing to shaping,

    int ap [10]; ap has an array of plastic elements 10,

    int * ap [31]; * ap is a shaping array has 31 elements, so ap is a pointer to such an array.

3. Non-array pointer

    Includes an address representative of a string constant all the characters in the string and a null character ( '\ 0') of the memory area

    strlen return parameters excluding the ending character '\ 0', so if a string after the application space strlen strcy,% s print string will hang.

4. null pointer is not empty string

            It can be used as a constant 0 to the pointer assignment, the same effect with NULL. This case (null pointer), the only operation of the pointer itself,

     Not attempt to use the contents of the pointer points stored in memory.

      if (p == (char *) 0) correctly;

      if (strcmp (p, (char *) 0)) error, strcmp can view the contents of realized pointer;

      Similarly, char * p = (char *) 0; printf ( "% s", p); wrong.

5. array actual address that does not exist "Overflow community" element of the array is located after the share memory, the address can be used for assignments and comparisons.

     int a[N] = { };

     a [N] is not present, but & a [N] is present.







发布了9 篇原创文章 · 获赞 6 · 访问量 1万+

Guess you like

Origin blog.csdn.net/sssuperqiqi/article/details/79567274